package com.bbcare.followup.plat.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import com.bbcare.comm.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.exceptions.JedisConnectionException;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bbcare.department.plat.entity.DepartmentBasic;
import com.bbcare.department.plat.store.ibatis.IDeparmentBasicDao;
import com.bbcare.followup.plat.entity.BodyTemperature;
import com.bbcare.followup.plat.entity.BodyTemperatureanalysis;
import com.bbcare.followup.plat.entity.BodyTemperaturedetail;
import com.bbcare.followup.plat.entity.FuAssessMentPosition;
import com.bbcare.followup.plat.entity.Oxygenpulserate;
import com.bbcare.followup.plat.entity.Oxygenpulserateanalysis;
import com.bbcare.followup.plat.entity.Oxygenpulseratedetail;
import com.bbcare.followup.plat.entity.Patient;
import com.bbcare.followup.plat.entity.PtDevelopstandardData;
import com.bbcare.followup.plat.entity.PtEvaluationGuide;
import com.bbcare.followup.plat.service.IFamilyReportService;
import com.bbcare.followup.plat.service.IFollowQueueService;
import com.bbcare.followup.plat.store.ibatis.IFamilyReportDAO;
import com.bbcare.followup.plat.store.ibatis.IFollowEvaluationDAO;
import com.bbcare.followup.plat.store.ibatis.IPatientDAO;

/**
 * @name: FamilyReportService.java
 * @author: tao
 * @createTime: 2017年4月24日
 * @description: 家庭数据监控接口实现类
 * @modify:
 */
@Service
public class FamilyReportService implements IFamilyReportService {
    private final Log logger = LogFactory.getLog(PatientService.class);
    @Autowired
    IFamilyReportDAO familyReportDAO;

    @Autowired
    private IDeparmentBasicDao deparmentBasicDao;

    @Autowired
    IPatientDAO patientdao;

    @Resource(name = "jedisPool")
    private JedisPool jedisPool;

    @Autowired
    private IFollowQueueService fllowQueueService;

    @Autowired
    IFollowEvaluationDAO followEvaluationDao;

    @Override
    public List<Map<String, Object>> getOxygenPulserateHistory(
            Map<String, Object> paramMap) throws Exception {

        int page = (paramMap.get("page") != null && !StringUtils.isEmpty(paramMap.get("page").toString())) ? Integer.parseInt(paramMap.get("page").toString()) : 1;
        int rows = (paramMap.get("rows") != null && !StringUtils.isEmpty(paramMap.get("rows").toString())) ? Integer.parseInt(paramMap.get("rows").toString()) : 10;

        paramMap.put("start", rows * (page - 1));
        paramMap.put("end", rows);
        paramMap.put("status", "01");

        List<Map<String, Object>> list = familyReportDAO.selectOxygenpulserateList(paramMap);
        Map<String, Object> map = null;
        if (!CollectionUtils.isEmpty(list)) {
            for (int i = 0; i < list.size(); i++) {
                map = list.get(i);
                list.get(i).put("startTime", DateUtil.getTimeStampSec(map.get("startTime").toString()));
                list.get(i).put("endTime", DateUtil.getTimeStampSec(map.get("endTime").toString()));
                map = null;
            }
        }
        return list;
    }

    @Override
    public List<Map<String, Object>> getOxygenPulserateHistoryByDay(
            Map<String, Object> paramMap) throws Exception {

        int page = (paramMap.get("page") != null && !StringUtils.isEmpty(paramMap.get("page").toString())) ? Integer.parseInt(paramMap.get("page").toString()) : 1;
        int rows = (paramMap.get("rows") != null && !StringUtils.isEmpty(paramMap.get("rows").toString())) ? Integer.parseInt(paramMap.get("rows").toString()) : 10;

        paramMap.put("start", rows * (page - 1));
        paramMap.put("end", rows);
        paramMap.put("status", "01");

        List<Map<String, Object>> list = familyReportDAO.selectOxygenpulserateListByDay(paramMap);
        return list;
    }

    @Override
    public Map<String, Object> getOxygenPulserateDetailByDay(
            Map<String, Object> paramMap) throws Exception {
        Map<String, Object> pulserateDetailMap = new HashMap<String, Object>();

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userId", paramMap.get("userId"));
        map.put("tenantId", paramMap.get("tenantId"));
        Patient patient = patientdao.selectById(map);
        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "患者信息不存在");
        }

        String birthday = patient.getBirthday();
        Integer pregnancyWeek = patient.getPregnancyDay();
//		Object testTime=pulserateDetailMap.get("startTime");

        List<Map<String, Object>> oxygenPulserateDetails = familyReportDAO.selectOxygenpulserateDetailsByDay(paramMap);
        Map<String, List<Map<String, Object>>> detailMap = new LinkedHashMap<String, List<Map<String, Object>>>();

        String key = "";
        if (!CollectionUtils.isEmpty(oxygenPulserateDetails)) {
            List<Map<String, Object>> list = null;
            for (int i = 0; i < oxygenPulserateDetails.size(); i++) {
                key = (String) oxygenPulserateDetails.get(i).get("oxygenPulserateId");
                if (detailMap.containsKey(key)) {
                    detailMap.get(key).add(oxygenPulserateDetails.get(i));
                } else {
                    list = new ArrayList<Map<String, Object>>();
                    list.add(oxygenPulserateDetails.get(i));
                    detailMap.put(key, list);
                }
            }
        }
        pulserateDetailMap.put("oxygenPulserateDetails", detailMap.values());

//		pulserateDetailMap.put("weekAge", age);
        pulserateDetailMap.put("birthday", birthday);
        pulserateDetailMap.put("userName", patient.getUserName());
        pulserateDetailMap.put("pregnancyDay", patient.getPregnancyDay());
        if (pregnancyWeek < 280) {
            pulserateDetailMap.put("userType", "01");//早产儿
        } else {
            pulserateDetailMap.put("userType", "02");
        }
        return pulserateDetailMap;
    }

    @Override
    public int getOxygenPulserateHistoryCountByDay(Map<String, Object> paramMap)
            throws Exception {
        paramMap.put("status", "01");
        return familyReportDAO.selectOxygenpulserateCount(paramMap);
    }

    @Override
    public Map<String, Object> getOxygenPulserateDetailById(
            Map<String, Object> paramMap) throws Exception {
        Map<String, Object> pulserateDetailMap = familyReportDAO.selectOxygenpulserate(paramMap);
        if (null == pulserateDetailMap || null == pulserateDetailMap.get("userId")) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PULSERATE_NOT_EXIST,
                    "氧饱脉率记录不存在");
        }

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userId", pulserateDetailMap.get("userId"));
        map.put("tenantId", paramMap.get("tenantId"));
        Patient patient = patientdao.selectById(map);
        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "患者信息不存在");
        }

        String birthday = patient.getBirthday();
        Integer pregnancyWeek = patient.getPregnancyDay();
        Long birthLong = ToolUtils.getCorrect(birthday, pregnancyWeek);//生日时间戳
        Object testTime = pulserateDetailMap.get("startTime");

        Date testdate = DateUtil.getDateA(testTime.toString());
        long age = (testdate.getTime() - birthLong) / (1000 * 60 * 60 * 24 * 7);

        List<Map<String, Object>> oxygenPulserateDetails = familyReportDAO.selectOxygenpulserateDetails(paramMap);
        pulserateDetailMap.put("oxygenPulserateDetails", oxygenPulserateDetails);
        pulserateDetailMap.put("weekAge", age);
        pulserateDetailMap.put("birthday", birthday);
        pulserateDetailMap.put("pregnancyDay", patient.getPregnancyDay());

        //时间转换
        pulserateDetailMap.put("startTime", DateUtil.getTimeStampSec(pulserateDetailMap.get("startTime").toString()));
        pulserateDetailMap.put("endTime", DateUtil.getTimeStampSec(pulserateDetailMap.get("endTime").toString()));
        pulserateDetailMap.put("testTime", DateUtil.getTimeStampSec(pulserateDetailMap.get("testTime").toString()));

        int perRateable = (null == pulserateDetailMap.get("perRateable")) ? 0 : Integer.parseInt(String.valueOf(pulserateDetailMap.get("perRateable")));
        int timeLong = (null == pulserateDetailMap.get("timeLong")) ? 0 : Integer.parseInt(String.valueOf(pulserateDetailMap.get("timeLong")));

        int normalTime = perRateable;
        pulserateDetailMap.put("pulseRateAbnormal", normalTime);
        if (timeLong - normalTime > 0) {
            pulserateDetailMap.put("pulseRateNormal", timeLong - normalTime);
        } else {
            pulserateDetailMap.put("pulseRateNormal", 0);
        }

        if (pregnancyWeek < 280) {
            pulserateDetailMap.put("userType", "01");//早产儿
        } else {
            pulserateDetailMap.put("userType", "02");
        }
        pulserateDetailMap.put("userName", patient.getUserName());
        return pulserateDetailMap;
    }

    @Override
    public int getOxygenPulserateHistoryCount(Map<String, Object> paramMap)
            throws Exception {
        paramMap.put("status", "01");
        return familyReportDAO.selectOxygenpulserateCount(paramMap);
    }

    @Override
    public List<Map<String, Object>> getBodytemperatureHistory(
            Map<String, Object> paramMap) throws Exception {
        int page = (paramMap.get("page") != null && !StringUtils.isEmpty(paramMap.get("page").toString())) ? Integer.parseInt(paramMap.get("page").toString()) : 1;
        int rows = (paramMap.get("rows") != null && !StringUtils.isEmpty(paramMap.get("rows").toString())) ? Integer.parseInt(paramMap.get("rows").toString()) : 10;

        paramMap.put("start", rows * (page - 1));
        paramMap.put("end", rows);
        paramMap.put("status", "01");

        List<Map<String, Object>> list = familyReportDAO.selectBodytemperatureList(paramMap);

        Map<String, Object> map = null;
        if (!CollectionUtils.isEmpty(list)) {
            for (int i = 0; i < list.size(); i++) {
                map = list.get(i);
                list.get(i).put("startTime", DateUtil.getTimeStampSec(map.get("startTime").toString()));
                list.get(i).put("endTime", DateUtil.getTimeStampSec(map.get("endTime").toString()));
                map = null;
            }
        }
        return list;
    }

    @Override
    public Map<String, Object> getBodytemperatureDetailById(
            Map<String, Object> paramMap) throws Exception {
        Map<String, Object> bodytemperatureDetailMap = familyReportDAO.selectBodytemperature(paramMap);
        if (null == bodytemperatureDetailMap || null == bodytemperatureDetailMap.get("userId")) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_TEMPERATURE_NOT_EXIST,
                    "体温记录不存在");
        }

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userId", bodytemperatureDetailMap.get("userId"));
        map.put("tenantId", paramMap.get("tenantId"));
//		map.put("status","1"));
        Patient patient = patientdao.selectById(map);
        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "患者信息不存在");
        }

        String birthday = patient.getBirthday();
        Integer pregnancyWeek = patient.getPregnancyDay();
        Long birthLong = ToolUtils.getCorrect(birthday, pregnancyWeek);//生日时间戳
        Object testTime = bodytemperatureDetailMap.get("startTime");

        Date testdate = DateUtil.getDateA(testTime.toString());
        long age = (testdate.getTime() - birthLong) / (1000 * 60 * 60 * 24 * 7);

        List<Map<String, Object>> bodytemperatureDetails = familyReportDAO.selectBodytemperatureDetails(paramMap);
        bodytemperatureDetailMap.put("bodyTemperatureDetails", bodytemperatureDetails);

        bodytemperatureDetailMap.put("weekAge", age);
        bodytemperatureDetailMap.put("birthday", birthday);
        bodytemperatureDetailMap.put("userName", patient.getUserName());

        bodytemperatureDetailMap.put("testTime", DateUtil.getTimeStampSec(bodytemperatureDetailMap.get("startTime").toString()));
        bodytemperatureDetailMap.put("endTime", DateUtil.getTimeStampSec(bodytemperatureDetailMap.get("endTime").toString()));

        if (pregnancyWeek < 280) {
            bodytemperatureDetailMap.put("userType", "01");//早产儿
        } else {
            bodytemperatureDetailMap.put("userType", "02");
        }
        return bodytemperatureDetailMap;
    }

    @Override
    public int getBodytemperatureHistoryCount(Map<String, Object> paramMap)
            throws Exception {
        paramMap.put("status", "01");
        return familyReportDAO.selectBodytemperatureCount(paramMap);
    }

    @Override
    public List<Map<String, Object>> getMonitorDataStatistics(Map<String, Object> paramMap)
            throws Exception {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        String type = null == paramMap.get("type") ? "" : (String) paramMap.get("type");
        Map<String, Object> map = null;

        // 根据当前登录账号获取，其可以查看的队列id
        int count = 0;
        int abnormalCount = 0;
        List<String> queueIdArray = fllowQueueService.getQueueArrByAuthority(paramMap);
        if (CollectionUtils.isEmpty(queueIdArray)) {
            logger.warn("该账号无可查看到的患者信息...arg==" + paramMap.toString());
            map = new HashMap<String, Object>();
            map.put("monitorCount", count);
            map.put("abnormalCount", abnormalCount);
            map.put("type", type);
            list.add(map);
            return list;
        }
        paramMap.put("queueIdIn", queueIdArray);
        paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);
        if (type.equals("1")) { //查氧饱
            map = new HashMap<String, Object>();
            count = familyReportDAO.countOxygenpulserateByAuthority(paramMap);
            paramMap.put("perOxyable", "100");//查异常
            abnormalCount = familyReportDAO.countOxygenpulserateByAuthority(paramMap);
            map.put("monitorCount", count);
            map.put("abnormalCount", abnormalCount);
            map.put("type", type);
            list.add(map);
        } else if (type.equals("2")) {//查脉率
            map = new HashMap<String, Object>();
            count = familyReportDAO.countOxygenpulserateByAuthority(paramMap);
            paramMap.put("perRateable", "100");//查异常
            abnormalCount = familyReportDAO.countOxygenpulserateByAuthority(paramMap);
            map.put("monitorCount", count);
            map.put("abnormalCount", abnormalCount);
            map.put("type", type);
            list.add(map);
        } else {//查体温
            map = new HashMap<String, Object>();
            count = familyReportDAO.countBodytemperatureByAuthority(paramMap);
            paramMap.put("pertop", "0");//查异常
            abnormalCount = familyReportDAO.countBodytemperatureByAuthority(paramMap);
            map.put("monitorCount", count);
            map.put("abnormalCount", abnormalCount);
            map.put("type", type);
            list.add(map);
        }
        return list;
    }

    @Override
    public List<Map<String, Object>> getmonitorTimesStatistics(Map<String, Object> paramMap)
            throws Exception {
        String type = null == paramMap.get("type") ? "" : (String) paramMap.get("type");
        String flag = null == paramMap.get("flag") ? "" : (String) paramMap.get("flag");

        String[] months = DateUtil.getLast6Months();
        String[] days = DateUtil.getLast7days();
        List<Map<String, Object>> rsplistN = new ArrayList<Map<String, Object>>();

        // 根据当前登录账号获取，其可以查看的队列id
        List<String> queueIdArray = fllowQueueService.getQueueArrByAuthority(paramMap);
        if (CollectionUtils.isEmpty(queueIdArray)) {
            logger.warn("该账号无可查看到的患者信息...arg==" + paramMap.toString());
            //返回数据均为0
            if ("1".equals(flag)) {//按月
                for (int i = 0; i < months.length; i++) {
                    Map<String, Object> mapTemp = new HashMap<String, Object>();
                    mapTemp.put("count", 0);
                    mapTemp.put("date", months[i]);
                    rsplistN.add(mapTemp);
                }
                return rsplistN;
            } else {
                for (int i = 0; i < days.length; i++) {
                    Map<String, Object> mapTemp = new HashMap<String, Object>();
                    mapTemp.put("count", 0);
                    mapTemp.put("date", days[i]);
                    rsplistN.add(mapTemp);
                }
                return rsplistN;
            }
        }

        paramMap.put("queueIdIn", queueIdArray);

        List<Map<String, Object>> rsplist = new ArrayList<Map<String, Object>>();

        if (type.equals("1")) { //查氧饱脉率
            if ("1".equals(flag)) {//按月
                //最近6月 按年月
                rsplist = familyReportDAO.countOxygenpulserateByAuthorityMonth(paramMap);
                Map<String, Object> mapQry = new HashMap<String, Object>();
                for (int j = 0; j < rsplist.size(); j++) {
                    mapQry.put(rsplist.get(j).get("date").toString(), rsplist.get(j).get("count"));
                }
                for (int i = 0; i < months.length; i++) {
                    Map<String, Object> mapTemp = new HashMap<String, Object>();

                    if (!mapQry.containsKey(months[i])) {
                        mapTemp.put("count", 0);
                        mapTemp.put("date", months[i]);
                        rsplistN.add(mapTemp);
                    } else {
                        mapTemp.put("count", mapQry.get(months[i]));
                        mapTemp.put("date", months[i]);
                        rsplistN.add(mapTemp);
                    }
                }
                return rsplistN;
            } else {
                //最近7天  按年月日
                rsplist = familyReportDAO.countOxygenpulserateByAuthorityDay(paramMap);

                Map<String, Object> mapQry = new HashMap<String, Object>();
                for (int j = 0; j < rsplist.size(); j++) {
                    mapQry.put(rsplist.get(j).get("date").toString(), rsplist.get(j).get("count"));
                }
                for (int i = 0; i < days.length; i++) {
                    Map<String, Object> mapTemp = new HashMap<String, Object>();
                    if (!mapQry.containsKey(days[i])) {
                        mapTemp.put("count", 0);
                        mapTemp.put("date", days[i]);
                        rsplistN.add(mapTemp);
                    } else {
                        mapTemp.put("count", mapQry.get(days[i]));
                        mapTemp.put("date", days[i]);
                        rsplistN.add(mapTemp);
                    }
                }
                return rsplistN;
            }
        } else {//查体温
            if ("1".equals(flag)) {//按月
                //最近6月 按年月
                rsplist = familyReportDAO.countBodytemperatureByAuthorityMonth(paramMap);
//				String [] months = DateUtil.getLast6Months();

                Map<String, Object> mapQry = new HashMap<String, Object>();
                for (int j = 0; j < rsplist.size(); j++) {
                    mapQry.put(rsplist.get(j).get("date").toString(), rsplist.get(j).get("count"));
                }
                for (int i = 0; i < months.length; i++) {
                    Map<String, Object> mapTemp = new HashMap<String, Object>();
                    if (!mapQry.containsKey(months[i])) {
                        mapTemp.put("count", 0);
                        mapTemp.put("date", months[i]);
                        rsplistN.add(mapTemp);
                    } else {
                        mapTemp.put("count", mapQry.get(months[i]));
                        mapTemp.put("date", months[i]);
                        rsplistN.add(mapTemp);
                    }
                }
                return rsplistN;
            } else {
                //最近7天  按年月日
                rsplist = familyReportDAO.countBodytemperatureByAuthorityDay(paramMap);

//				String [] days = DateUtil.getLast7days();

                Map<String, Object> mapQry = new HashMap<String, Object>();
                for (int j = 0; j < rsplist.size(); j++) {
                    mapQry.put(rsplist.get(j).get("date").toString(), rsplist.get(j).get("count"));
                }
                for (int i = 0; i < days.length; i++) {
                    Map<String, Object> mapTemp = new HashMap<String, Object>();
                    if (!mapQry.containsKey(days[i])) {
                        mapTemp.put("count", 0);
                        mapTemp.put("date", days[i]);
                        rsplistN.add(mapTemp);
                    } else {
                        mapTemp.put("count", mapQry.get(days[i]));
                        mapTemp.put("date", days[i]);
                        rsplistN.add(mapTemp);
                    }
                }
                return rsplistN;
            }
        }
    }

    @Override
    public Map<String, Object> getpatientsStatistics(
            Map<String, Object> paramMap) throws Exception {
        Map<String, Object> rspMap = new HashMap<String, Object>();
        String type = null == paramMap.get("type") ? "" : (String) paramMap.get("type");

        // 根据当前登录账号获取，其可以查看的队列id
        List<String> queueIdArray = fllowQueueService.getQueueArrByAuthority(paramMap);

        int abnormalTimes = 0;
        int dayTestPatients = 0;
        int totalTestPatients = 0;
        int totalTestTimes = 0;

        String tenantId = (String) paramMap.get("tenantId");

        if (CollectionUtils.isEmpty(queueIdArray)) {
            logger.warn("该账号无可查看到的患者信息...arg==" + paramMap.toString());
            rspMap.put("abnormalTimes", abnormalTimes);
            rspMap.put("dayTestPatients", dayTestPatients);
            rspMap.put("totalTestPatients", totalTestPatients);
            rspMap.put("totalTestTimes", totalTestTimes);
            return rspMap;
        }

        paramMap.put("queueIdIn", queueIdArray);
        paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);

        if (type.equals("1")) {
            //体温
            totalTestTimes = familyReportDAO.countBodytemperatureByAuthority(paramMap);//总数

            paramMap.put("pertop", "0");//查异常
            abnormalTimes = familyReportDAO.countBodytemperatureByAuthority(paramMap);

            paramMap.clear();
            paramMap.put("tenantId", tenantId);
            paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);
            paramMap.put("queueIdIn", queueIdArray);

            totalTestPatients = familyReportDAO.countTemperaturePatientList(paramMap);
            paramMap.put("isToday", true);
            dayTestPatients = familyReportDAO.countBodytemperatureByAuthority(paramMap);

            rspMap.put("abnormalTimes", abnormalTimes);
            rspMap.put("dayTestPatients", dayTestPatients);
            rspMap.put("totalTestPatients", totalTestPatients);
            rspMap.put("totalTestTimes", totalTestTimes);

        } else if (type.equals("2")) {
            //氧饱脉率
            totalTestTimes = familyReportDAO.countOxygenpulserateByAuthority(paramMap);

            paramMap.put("perOxyable", "100");
            paramMap.put("perRateable", "100");//氧饱或者脉率有异常就算异常
            abnormalTimes = familyReportDAO.countOxygenpulserateByAuthority(paramMap);

            paramMap.clear();
            paramMap.put("tenantId", tenantId);
            paramMap.put("queueIdIn", queueIdArray);
            paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);
            totalTestPatients = familyReportDAO.countOxygenpulseratePatientList(paramMap);

            paramMap.put("isToday", true);
            dayTestPatients = familyReportDAO.countOxygenpulserateByAuthority(paramMap);

            rspMap.put("abnormalTimes", abnormalTimes);
            rspMap.put("dayTestPatients", dayTestPatients);
            rspMap.put("totalTestPatients", totalTestPatients);
            rspMap.put("totalTestTimes", totalTestTimes);
        } else if (type.equals("3")) {
            //生长发育
            paramMap.put("appSourceType", Constants.PT_USER_INFO_DEFAULT_TENANT_ID);//加上患者app自己录入的数据
            totalTestTimes = familyReportDAO.countGrowthByAuthority(paramMap);

//			abnormalTimes = familyReportDAO.countOxygenpulserateByAuthority(paramMap);

            paramMap.clear();
            paramMap.put("tenantId", tenantId);
            paramMap.put("queueIdIn", queueIdArray);
            paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);
            paramMap.put("appSourceType", Constants.PT_USER_INFO_DEFAULT_TENANT_ID);//加上患者app自己录入的数据
            totalTestPatients = familyReportDAO.countGrowthPatientList(paramMap);

            paramMap.put("isToday", true);
            paramMap.put("appSourceType", Constants.PT_USER_INFO_DEFAULT_TENANT_ID);//加上患者app自己录入的数据
            dayTestPatients = familyReportDAO.countGrowthByAuthority(paramMap);

            rspMap.put("abnormalTimes", abnormalTimes);
            rspMap.put("dayTestPatients", dayTestPatients);
            rspMap.put("totalTestPatients", totalTestPatients);
            rspMap.put("totalTestTimes", totalTestTimes);
        }
        return rspMap;
    }

    @Override
    public List<Map<String, Object>> getBodyTemperaturePatientList(
            Map<String, Object> paramMap) throws Exception {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        String queueId = ((paramMap.get("queueId") != null && !StringUtils.isEmpty(paramMap.get("queueId").toString()))) ? paramMap.get("queueId").toString() : null;

        List<String> queueIdArray = new ArrayList<String>();
        if (StringUtils.isEmpty(queueId)) {
            // 根据当前登录账号获取，其可以查看的队列id
            queueIdArray = fllowQueueService.getQueueArrByAuthority(paramMap);
            if (CollectionUtils.isEmpty(queueIdArray)) {
                logger.warn("该账号无可查看到的患者信息...arg==" + paramMap.toString());
                return list;
            }
        } else {
            queueIdArray.add(queueId);
        }

        paramMap.put("queueIdIn", queueIdArray);
        paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);
        int page = (paramMap.get("page") != null && !StringUtils.isEmpty(paramMap.get("page").toString())) ? Integer.parseInt(paramMap.get("page").toString()) : 1;
        int rows = (paramMap.get("rows") != null && !StringUtils.isEmpty(paramMap.get("rows").toString())) ? Integer.parseInt(paramMap.get("rows").toString()) : 10;

        paramMap.put("start", rows * (page - 1));
        paramMap.put("end", rows);
        Object userNameObject = paramMap.get("userName");
        Object userName = (userNameObject != null && !StringUtils.isEmpty(userNameObject)) ? "%" + userNameObject.toString() + "%" : userNameObject;

        paramMap.put("userName", userName);
        list = familyReportDAO.selectTemperaturePatientList(paramMap);
        Map<String, Object> map = null;
        if (!CollectionUtils.isEmpty(list)) {
            for (int i = 0; i < list.size(); i++) {
                map = list.get(i);
                list.get(i).put("testTime", DateUtil.getTimeStampSec(map.get("testTime").toString()));
                list.get(i).put("testTimeDesc", DateUtil.formatTimedifference(map.get("testTime").toString()));
                map = null;
            }
        }
        return list;
    }

    @Override
    public List<Map<String, Object>> getOxygenPulseratePatientList(
            Map<String, Object> paramMap) throws Exception {

        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        String queueId = ((paramMap.get("queueId") != null && !StringUtils.isEmpty(paramMap.get("queueId").toString()))) ? paramMap.get("queueId").toString() : null;

        List<String> queueIdArray = new ArrayList<String>();
        if (StringUtils.isEmpty(queueId)) {
            // 根据当前登录账号获取，其可以查看的队列id
            queueIdArray = fllowQueueService.getQueueArrByAuthority(paramMap);
            if (CollectionUtils.isEmpty(queueIdArray)) {
                logger.warn("该账号无可查看到的患者信息...arg==" + paramMap.toString());
                return list;
            }
        } else {
            queueIdArray.add(queueId);
        }

        paramMap.put("queueIdIn", queueIdArray);
        paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);

        int page = (paramMap.get("page") != null && !StringUtils.isEmpty(paramMap.get("page").toString())) ? Integer.parseInt(paramMap.get("page").toString()) : 1;
        int rows = (paramMap.get("rows") != null && !StringUtils.isEmpty(paramMap.get("rows").toString())) ? Integer.parseInt(paramMap.get("rows").toString()) : 10;

        paramMap.put("start", rows * (page - 1));
        paramMap.put("end", rows);

        Object userNameObject = paramMap.get("userName");
        Object userName = (userNameObject != null && !StringUtils.isEmpty(userNameObject)) ? "%" + userNameObject.toString() + "%" : userNameObject;

        paramMap.put("userName", userName);
        list = familyReportDAO.selectOxygenpulseratePatientList(paramMap);
        Map<String, Object> map = null;
        if (!CollectionUtils.isEmpty(list)) {
            for (int i = 0; i < list.size(); i++) {
                map = list.get(i);
                list.get(i).put("testTime", DateUtil.getTimeStampSec(map.get("testTime").toString()));
                list.get(i).put("testTimeDesc", DateUtil.formatTimedifference(map.get("testTime").toString()));
                map = null;
            }
        }
        return list;
    }

    @Override
    public int getOxygenPulseratePatientCount(Map<String, Object> paramMap)
            throws Exception {
        paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);
        return familyReportDAO.countOxygenpulseratePatientList(paramMap);
    }

    @Override
    public int getBodyTemperaturePatientCount(Map<String, Object> paramMap)
            throws Exception {
        paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);
        return familyReportDAO.countTemperaturePatientList(paramMap);
    }

    @Override
    public List<Map<String, Object>> getGrowthPatientList(
            Map<String, Object> paramMap) throws Exception {

        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        String queueId = ((paramMap.get("queueId") != null && !StringUtils.isEmpty(paramMap.get("queueId").toString()))) ? paramMap.get("queueId").toString() : null;

        List<String> queueIdArray = new ArrayList<String>();
        if (StringUtils.isEmpty(queueId)) {
            // 根据当前登录账号获取，其可以查看的队列id
            queueIdArray = fllowQueueService.getQueueArrByAuthority(paramMap);
            if (CollectionUtils.isEmpty(queueIdArray)) {
                logger.warn("该账号无可查看到的患者信息...arg==" + paramMap.toString());
                return list;
            }
        } else {
            queueIdArray.add(queueId);
        }

        paramMap.put("queueIdIn", queueIdArray);
        paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);

        int page = (paramMap.get("page") != null && !StringUtils.isEmpty(paramMap.get("page").toString())) ? Integer.parseInt(paramMap.get("page").toString()) : 1;
        int rows = (paramMap.get("rows") != null && !StringUtils.isEmpty(paramMap.get("rows").toString())) ? Integer.parseInt(paramMap.get("rows").toString()) : 10;

        paramMap.put("start", rows * (page - 1));
        paramMap.put("end", rows);

        Object userNameObject = paramMap.get("userName");
        Object userName = (userNameObject != null && !StringUtils.isEmpty(userNameObject)) ? "%" + userNameObject.toString() + "%" : userNameObject;

        paramMap.put("userName", userName);
        list = familyReportDAO.selectGrowthPatientList(paramMap);
        Map<String, Object> map = null;
        if (!CollectionUtils.isEmpty(list)) {
            for (int i = 0; i < list.size(); i++) {
                map = list.get(i);
                //监测时间
                list.get(i).put("testTime", map.get("testTime").toString());
                //录入时间
                list.get(i).put("testTimeDesc", DateUtil.formatTimedifference(map.get("createTime").toString()));
                map = null;
            }
        }
        return list;
    }

    @Override
    public int getGrowthPatientCount(Map<String, Object> paramMap)
            throws Exception {
        paramMap.put("userStatus", Constants.QUEUE_STATUS_NOMAL);
        return familyReportDAO.countGrowthPatientList(paramMap);
    }

    @Override
    public List<Map<String, Object>> getGrowthHistory(
            Map<String, Object> paramMap) throws Exception {

        Map<String, Object> usermap = new HashMap<String, Object>();
        usermap.put("userId", paramMap.get("userId"));
        usermap.put("tenantId", paramMap.get("tenantId"));
//		map.put("status","1"));
        Patient patient = patientdao.selectById(usermap);

        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "生长发育评估记录患者信息不存在");
        }

        int page = (paramMap.get("page") != null && !StringUtils.isEmpty(paramMap.get("page").toString())) ? Integer.parseInt(paramMap.get("page").toString()) : 1;
        int rows = (paramMap.get("rows") != null && !StringUtils.isEmpty(paramMap.get("rows").toString())) ? Integer.parseInt(paramMap.get("rows").toString()) : 10;

        if (Constants.SOURCE_TYPE_APP.equals(paramMap.get("sourseType"))) {

        } else {
            paramMap.put("start", rows * (page - 1));
            paramMap.put("end", rows);
            paramMap.put("status", "01");
        }

        List<Map<String, Object>> list = familyReportDAO.selectGrowthList(paramMap);
        String testTime = null;
        String testAge = null;
        Map<String, Object> map = null;
        if (!CollectionUtils.isEmpty(list)) {
            for (int i = 0; i < list.size(); i++) {
                map = list.get(i);
                if (null != map.get("testTime")) {
                    testTime = map.get("testTime").toString();
                    if (!StringUtils.isEmpty(patient.getBirthday())) {
                        testAge = ToolUtils.getAgeByDate(patient.getBirthday(), DateUtil.getDate_8(testTime));
                        list.get(i).put("testAge", testAge);
                        list.get(i).put("birthday", patient.getBirthday());
                        list.get(i).put("pregnancyWeek", patient.getPregnancyDay());
                        list.get(i).put("type", Constants.FOLLOW_EVALUATION_PREGNANT_GROWTH);
                    }
                    list.get(i).put("testTime", DateUtil.getTimeStampSec(testTime));
                    list.get(i).put("createTime", DateUtil.getTimeStampSec(testTime));
                    list.get(i).put("userName", patient.getUserName());
                }
                map.put("expectedDay", patient.getExpectedDay());
                map.put("gender", patient.getGender());

                map = null;
            }
        }
        return list;
    }

    @Override
    public Map<String, Object> getGrowthDeatail(
            Map<String, Object> paramMap) throws Exception {
        Map<String, Object> growthDetailsMap = familyReportDAO.selectGrowthDetails(paramMap);
        if (null == growthDetailsMap || null == growthDetailsMap.get("userId")) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_TEMPERATURE_NOT_EXIST,
                    "评估记录不存在");
        }

        //查询曲线类型 条件输入
        String scoreType = (String) paramMap.get("scoreType");
        String ageType = (String) paramMap.get("ageType");

        String tenantId = (String) paramMap.get("tenantId");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userId", growthDetailsMap.get("userId"));
        map.put("tenantId", tenantId);
//		map.put("status","1"));
        Patient patient = patientdao.selectById(map);
        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "生长发育评估记录患者信息不存在");
        }

        String birthday = patient.getBirthday();
//		Date birthdayDate = DateUtil.getDate_8(birthday);
        Integer pregnancyWeek = patient.getPregnancyDay();
        Long birthLong = ToolUtils.getCorrect(birthday, pregnancyWeek);//生日时间戳
        Object testTime = growthDetailsMap.get("testTime");
        Date testdate = DateUtil.getDate_8(testTime.toString());
        long ageGuid = (testdate.getTime() - birthLong) / (1000 * 60 * 60 * 24); //纠正年龄 指导方案时候使用
        Date date = new Date(birthLong);
        growthDetailsMap.put("weekAge", ToolUtils.getAgeByBirthday(DateUtil.getDate_8(date)));//纠正
        growthDetailsMap.put("birthday", birthday);
        growthDetailsMap.put("gender", patient.getGender());
        growthDetailsMap.put("createTime", DateUtil.getTimeStampSec(growthDetailsMap.get("createTime").toString()));
        growthDetailsMap.put("testTime", DateUtil.getTimeStampSec(growthDetailsMap.get("testTime").toString()));
        growthDetailsMap.put("userName", patient.getUserName());
        growthDetailsMap.put("pregnancyDay", patient.getPregnancyDay());
        if (null == growthDetailsMap.get("doctorName")) {
            growthDetailsMap.put("doctorName", paramMap.get("doctorName"));
        } else {
            growthDetailsMap.put("doctorName", growthDetailsMap.get("doctorName"));
        }

        //根据租户ID 查询科室名称和医院名称
        String deptId = (String) paramMap.get("deptId");
        DepartmentBasic departMent = deparmentBasicDao.selectById(deptId);
        if (null != departMent) {
            growthDetailsMap.put("departmentName", departMent.getDeptName());
            growthDetailsMap.put("hospName", departMent.getHospName());
        }

        //指导方案获取  指导方案根据纠正年龄获取

        Map<String, Object> guidMap = new HashMap<String, Object>();
        guidMap.put("questionModuleId", Constants.QUESTION_MODULE_ID_GROWTH);
        guidMap.put("age", ageGuid);
        List<Map<String, Object>> guidDetailMapList = familyReportDAO.selectHealthGuideDetail(guidMap);
        growthDetailsMap.put("guideDetails", guidDetailMapList);

        Map<String, Object> weightMap = new HashMap<String, Object>();
        Map<String, Object> lengthMap = new HashMap<String, Object>();
        Map<String, Object> headMap = new HashMap<String, Object>();
        Map<String, Object> lengthForWttMap = new HashMap<String, Object>();
        Map<String, Object> ageForWtMap = new HashMap<String, Object>();

        long ageDay = 0;
        map.put("testTime", DateUtil.getTimeStampSec(growthDetailsMap.get("testTime").toString()));


        if (!getScale(patient, testdate, ageType)) {
            if (Constants.GROWTH_AGE_TYPE_ACTUAL.equals(ageType)) {//按实际年龄计算  重新计算年龄
                birthLong = DateUtil.getDate_8(birthday).getTime();
            }
            ageDay = (testdate.getTime() - birthLong) / (1000 * 60 * 60 * 24);
            //查询who标准数据
            Map<String, Object> whoMap = new HashMap<String, Object>();
            whoMap.put("age", ageDay);
            whoMap.put("gender", patient.getGender());
            whoMap.put("standardId", Constants.WHO_STANDARD_ID);
            whoMap.put("length", growthDetailsMap.get("hight"));

            whoMap.put("standardType", Constants.WHO_STANDARD_TYPE_PERCENT);
            if (Constants.GROWTH_SCORE_ZSCORE.equals(scoreType)) {//如果计算zscore 则传zscore类型
                whoMap.put("standardType", Constants.WHO_STANDARD_TYPE_SCORE);
            }

            List<Map<String, Object>> whoMaplist = familyReportDAO.selectDevelopStandardForWho(whoMap);
            if (!CollectionUtils.isEmpty(whoMaplist)) {
                Map<String, Object> temp = null;
                for (int i = 0; i < whoMaplist.size(); i++) { //各项标准数据
                    temp = whoMaplist.get(i);
                    if (Constants.DEVELOPPROJECT_HEAD.equals(temp.get("developProject_id"))) {
                        headMap.putAll(temp);
                    } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(temp.get("developProject_id"))) {
                        ageForWtMap.putAll(temp);
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(temp.get("developProject_id"))) {
                        lengthMap.putAll(temp);
                    } else if (Constants.DEVELOPPROJECT_LENGTHFORWEIGHT.equals(temp.get("developProject_id"))) {
                        lengthForWttMap.putAll(temp);
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(temp.get("developProject_id"))) {
                        weightMap.putAll(temp);
                    }
                }
            } else {
                //年龄超过标准曲线范围
            }
            growthDetailsMap.put("weightSummary", weightMap);
            growthDetailsMap.put("hightSummary", lengthMap);
            growthDetailsMap.put("headSummary", headMap);
            growthDetailsMap.put("weightForLength", lengthForWttMap);
            growthDetailsMap.put("curveType", Constants.GROWTH_CURVEDATA_LINES);

            if ((float) ageDay / 365 >= 2) {
                growthDetailsMap.put("ageForWtMap", ageForWtMap);
            }

            Map<String, List<Map<String, Object>>> result = new HashMap<String, List<Map<String, Object>>>();
            if (!StringUtils.isEmpty(growthDetailsMap.get("weight"))) {
                map.put("type", Constants.DEVELOPPROJECT_WEIGHT);
                map.put("values", growthDetailsMap.get("weight"));
                List<Map<String, Object>> actualList = getGrowthResult(ageType, map, patient);
                if (!CollectionUtils.isEmpty(actualList)) {
                    result.put("weightResult", actualList);
                }
            }
            if (!StringUtils.isEmpty(growthDetailsMap.get("hight"))) {
                map.put("type", Constants.DEVELOPPROJECT_LENGTH);
                map.put("values", growthDetailsMap.get("hight"));
                List<Map<String, Object>> actualList = getGrowthResult(ageType, map, patient);
                if (!CollectionUtils.isEmpty(actualList)) {
                    result.put("heightResult", actualList);
                }
            }
            if (!StringUtils.isEmpty(growthDetailsMap.get("headCircumference"))) {
                map.put("values", growthDetailsMap.get("headCircumference"));
                map.put("type", Constants.DEVELOPPROJECT_HEAD);
                List<Map<String, Object>> actualList = getGrowthResult(ageType, map, patient);
                if (!CollectionUtils.isEmpty(actualList)) {
                    result.put("headtResult", actualList);
                }
            }
            growthDetailsMap.put("result", JSON.toJSONString(result));
        } else {
            //fenton曲线查询
            //调用fenton曲线  早产儿 并且 监测时胎龄<50周  其他走正常曲线
            birthLong = DateUtil.getDate_8(patient.getBirthday()).getTime();//生日时间戳
            ageDay = (testdate.getTime() - birthLong) / (1000 * 60 * 60 * 24);
            ageDay = patient.getPregnancyDay() + ageDay; //实际胎龄

            //查询who标准数据
            Map<String, Object> whoMap = new HashMap<String, Object>();
            whoMap.put("age", ageDay);
            whoMap.put("gender", patient.getGender());
            whoMap.put("standardId", Constants.WHO_STANDARD_ID);
            whoMap.put("length", growthDetailsMap.get("hight"));

            whoMap.put("standardType", Constants.FENTON_STANDARD_TYPE_PERCENT);
            if (Constants.GROWTH_SCORE_ZSCORE.equals(scoreType)) {//如果计算zscore 则传zscore类型
                whoMap.put("standardType", Constants.FENTON_STANDARD_TYPE_SCORE);
            }

            List<Map<String, Object>> whoMaplist = familyReportDAO.selectDevelopStandardForWho(whoMap);
            if (!CollectionUtils.isEmpty(whoMaplist)) {
                Map<String, Object> temp = null;
                for (int i = 0; i < whoMaplist.size(); i++) { //各项标准数据
                    temp = whoMaplist.get(i);
                    if (Constants.DEVELOPPROJECT_HEAD.equals(temp.get("developProject_id"))) {
                        headMap.putAll(temp);
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(temp.get("developProject_id"))) {
                        lengthMap.putAll(temp);
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(temp.get("developProject_id"))) {
                        weightMap.putAll(temp);
                    }
                }
            } else {
                //年龄超过标准曲线范围
            }
            growthDetailsMap.put("weightSummary", weightMap);
            growthDetailsMap.put("hightSummary", lengthMap);
            growthDetailsMap.put("headSummary", headMap);
            growthDetailsMap.put("curveType", Constants.FENTON_CURVEDATA_LINES);

            Map<String, List<Map<String, Object>>> result = new HashMap<String, List<Map<String, Object>>>();
            if (!StringUtils.isEmpty(growthDetailsMap.get("weight"))) {
                map.put("type", Constants.DEVELOPPROJECT_WEIGHT);
                map.put("values", growthDetailsMap.get("weight"));
                List<Map<String, Object>> actualList = getGrowthResult(ageType, map, patient);
                if (!CollectionUtils.isEmpty(actualList)) {
                    result.put("weightResult", actualList);
                }
            }
            if (!StringUtils.isEmpty(growthDetailsMap.get("hight"))) {
                map.put("type", Constants.DEVELOPPROJECT_LENGTH);
                map.put("values", growthDetailsMap.get("hight"));
                List<Map<String, Object>> actualList = getGrowthResult(ageType, map, patient);
                if (!CollectionUtils.isEmpty(actualList)) {
                    result.put("heightResult", actualList);
                }
            }
            if (!StringUtils.isEmpty(growthDetailsMap.get("headCircumference"))) {
                map.put("values", growthDetailsMap.get("headCircumference"));
                map.put("type", Constants.DEVELOPPROJECT_HEAD);
                List<Map<String, Object>> actualList = getGrowthResult(ageType, map, patient);
                if (!CollectionUtils.isEmpty(actualList)) {
                    result.put("headtResult", actualList);
                }
            }
            growthDetailsMap.put("result", JSON.toJSONString(result));
            growthDetailsMap.put("actualResult", JSON.toJSONString(result));
        }

        growthDetailsMap.put("ageType", ageType);
        growthDetailsMap.put("scoreType", scoreType);
        return growthDetailsMap;
    }

    @Override
    @Transactional
    public int save(Map<String, Object> list) throws Exception {
        return familyReportDAO.save(list);
    }

    @Override
    @Transactional
    public int save(List<PtDevelopstandardData> list) throws Exception {
        return familyReportDAO.savePercent(list);
    }

    @Override
    public Map<String, Object> getGrowthCurvedata(final Map<String, Object> paramMap) throws Exception {
        //返回曲线数据
        List<Map<String, Object>> rsp = new ArrayList<Map<String, Object>>();
        Map<String, Object> curaDataMap = new HashMap<String, Object>();

        //查询曲线类型 条件输入
        String flagType = (String) paramMap.get("flag");
        String type = (String) paramMap.get("type");
        String scoreType = (String) paramMap.get("scoreType");
        String ageType = (String) paramMap.get("ageType");
        String valueFlag = (String) paramMap.get("valueFlag");
//		Map<String, Object> infoMap = new HashMap<String, Object>();

        Map<String, Object> weightMap = new HashMap<String, Object>();
        Map<String, Object> lengthMap = new HashMap<String, Object>();
        Map<String, Object> headMap = new HashMap<String, Object>();
        Map<String, Object> lengthForWttMap = new HashMap<String, Object>();
        Map<String, Object> ageForWtMap = new HashMap<String, Object>();

        Map<String, Object> userPara = new HashMap<String, Object>();
        userPara.put("userId", paramMap.get("userId"));
        userPara.put("tenantId", paramMap.get("tenantId"));
//		map.put("status","1"));
        Patient patient = patientdao.selectById(userPara);
        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST, "生长发育评估记录患者信息不存在");
        }

        final String birthday = patient.getBirthday();
        if (null == birthday) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_BIRTHDAY_NOT_EXIST, "用户没有出生日期");
        }

        final int pregnancyDay = patient.getPregnancyDay();
        final Object testTimeObj = paramMap.get("testTime");
        Long birthLong = 0L;
        if (null == testTimeObj) {
            birthLong = ToolUtils.getCorrect(birthday, pregnancyDay);//生日时间戳
        } else {
            Map<String, Object> ageMap = new HashMap<>();
            ageMap.put("birthday", birthday);
            ageMap.put("pregnancyDay", pregnancyDay);
            ageMap.put("checkDate", testTimeObj.toString());
            birthLong = ToolUtils.getCorrectCheckAge(ageMap);
        }

        List<Map<String, Object>> growthDetailsList = familyReportDAO.selectGrowthDetailsByUserId(paramMap);

        Object testTimeHis = null;
        Object testTime = null;  //本次监测时间  计算出统计单位   周 、月 、年
        if (StringUtils.isEmpty(type)) { // type为空 则根据生长发育记录查询
            if (!CollectionUtils.isEmpty(growthDetailsList)) {
                for (int j = 0; j < growthDetailsList.size(); j++) {
                    if (growthDetailsList.get(j).get("growthRecordId").equals(paramMap.get("growthRecordId"))) {
                        //当前记录
                        testTime = growthDetailsList.get(j).get("testTime");
                    }
                }
            }
        } else {
            testTime = paramMap.get("testTime");//身高体重查询曲线  必须传入监测时间
        }

        //计算当前节点X轴
        long endTime = 0;
        long endTimeHis = 0;
        if (null == testTime) {
            testTime = DateUtil.getDate_8(new Date());
        }
        Date testdate = DateUtil.getDate_8(testTime.toString());


        if (!getScale(patient, testdate, ageType)) {
            //只有按纠正年龄计算时 并且  纠正年龄为负 才会走fenton曲线
            //if(Constants.GROWTH_AGE_TYPE_ACTUAL.equals(ageType) || testdate.getTime()-birthLong > 0){
            if (Constants.GROWTH_AGE_TYPE_ACTUAL.equals(ageType)) {//按实际年龄计算  重新计算年龄
                birthLong = DateUtil.getDate_8(birthday).getTime();
            }
            endTime = (testdate.getTime() - birthLong) / (1000 * 60 * 60 * 24);
            float yearDay = 365F;
            if ((float) endTime / yearDay <= 5) { //小于5岁
                int xMin = 0;
                int xMax = 0;
                String timeUnit = "周";
                String redisKey = Constants.WHO_STANDARD_TYPE_PERCENT;
                String redisKeyLfW = Constants.WHO_STANDARD_TYPE_PERCENT;
                if (Constants.GROWTH_SCORE_ZSCORE.equals(scoreType)) {
                    redisKey = Constants.WHO_STANDARD_TYPE_SCORE;
                    redisKeyLfW = Constants.WHO_STANDARD_TYPE_SCORE;
                }
                //每个月 平均天数
                float monthDay = 30.4F;
                float weekDay = 7F;
                float xdate = 0, timeUnitLong = 0;
//				Object testTimeHis=null;
                if ((float) endTime / monthDay <= 6) {//6个月以内  半年~26周
                    xMax = 26; //取24周的数据
                    timeUnit = "周";
                    redisKey += "_WEEK";
                    timeUnitLong = weekDay;

                    lengthForWttMap.put("xMax", 110);
                    lengthForWttMap.put("xMin", 45);
                    lengthForWttMap.put("timeUnit", "cm");
                } else if ((float) endTime / monthDay > 6 && (float) endTime / yearDay <= 2) {
                    xMax = 24; //24月数据
                    timeUnit = "月";
                    timeUnitLong = monthDay;
                    redisKey += "_MONTH";
                    lengthForWttMap.put("xMax", 110);
                    lengthForWttMap.put("xMin", 45);
                    lengthForWttMap.put("timeUnit", "cm");
                } else if ((float) endTime / yearDay > 2 && (float) endTime / yearDay <= 5) { //2-5岁   或者大于5
                    xMax = 5; //5年
                    timeUnit = "年";
                    timeUnitLong = yearDay;
                    redisKey += "_YEAR";
                    ageForWtMap.put("xMax", xMax);
                    ageForWtMap.put("xMin", 0);
                    ageForWtMap.put("timeUnit", timeUnit);
                } else if ((float) endTime / yearDay > 5) {
                    xMax = 19; //5-19月
                    xMin = 5;
                    timeUnit = "年";
                    timeUnitLong = yearDay;
                    redisKey += "_FIVE_YEAR";
                    ageForWtMap.put("xMax", xMax);
                    ageForWtMap.put("xMin", xMin);
                    ageForWtMap.put("timeUnit", timeUnit);
                }

                weightMap.put("xMax", xMax);
                weightMap.put("xMin", xMin);
                weightMap.put("timeUnit", timeUnit);

                lengthMap.put("xMax", xMax);
                lengthMap.put("xMin", xMin);
                lengthMap.put("timeUnit", timeUnit);

                headMap.put("xMax", xMax);
                headMap.put("xMin", xMin);
                headMap.put("timeUnit", timeUnit);

                List<Map<String, Object>> hights = new ArrayList<Map<String, Object>>();
                List<Map<String, Object>> weights = new ArrayList<Map<String, Object>>();
                List<Map<String, Object>> heads = new ArrayList<Map<String, Object>>();
                List<Map<String, Object>> hfws = new ArrayList<Map<String, Object>>();
                List<Map<String, Object>> wfas = new ArrayList<Map<String, Object>>();

                Map<String, Object> map = null;
                Map<String, Object> growthDetailsMap = null;
                xdate = (float) endTime / timeUnitLong;
                if (!StringUtils.isEmpty(type)) {
                    if (StringUtils.isEmpty(valueFlag)) {
                        map = new HashMap<String, Object>();
                        map.put("xDate", xdate);
                        map.put("yDate", paramMap.get("values"));
                        map.put("flag", 1);
                        try {
                            List<Map<String, Object>> list = getGrowthResult(ageType, paramMap, patient);
                            map.put("result", JSON.toJSONString(list));
                        } catch (Exception e) {
                            logger.error("计算百分位有误", e);
                        }

                        if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                            heads.add(map);
                        } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                            weights.add(map);
                        } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                            hights.add(map);
                        } else {
                            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "type值不符合定义类型");
                        }
                    } else {
                        Object weight = paramMap.get("weight");
                        if (!StringUtils.isEmpty(weight)) {
                            map = new HashMap<String, Object>();
                            map.put("xDate", xdate);
                            map.put("yDate", weight);
                            map.put("flag", 1);
                            try {
                                paramMap.put("values", weight);
                                paramMap.put("type", Constants.DEVELOPPROJECT_WEIGHT);
                                List<Map<String, Object>> list = getGrowthResult(ageType, paramMap, patient);
                                map.put("result", JSON.toJSONString(list));
                            } catch (Exception e) {
                                logger.error("计算百分位有误", e);
                            }
                            weights.add(map);
                        }

                        Object height = paramMap.get("hight");
                        if (!StringUtils.isEmpty(height)) {
                            map = new HashMap<String, Object>();
                            map.put("xDate", xdate);
                            map.put("yDate", height);
                            map.put("flag", 1);
                            try {
                                paramMap.put("values", height);
                                paramMap.put("type", Constants.DEVELOPPROJECT_LENGTH);
                                List<Map<String, Object>> list = getGrowthResult(ageType, paramMap, patient);
                                map.put("result", JSON.toJSONString(list));
                            } catch (Exception e) {
                                logger.error("计算百分位有误", e);
                            }
                            hights.add(map);
                        }

                        Object head = paramMap.get("headCircumference");
                        if (!StringUtils.isEmpty(head)) {
                            map = new HashMap<String, Object>();
                            map.put("xDate", xdate);
                            map.put("yDate", head);
                            map.put("flag", 1);
                            try {
                                paramMap.put("values", head);
                                paramMap.put("type", Constants.DEVELOPPROJECT_HEAD);
                                List<Map<String, Object>> list = getGrowthResult(ageType, paramMap, patient);
                                map.put("result", JSON.toJSONString(list));
                            } catch (Exception e) {
                                logger.error("计算百分位有误", e);
                            }
                            heads.add(map);
                        }

                        map = new HashMap<String, Object>();
                        if (null != weight && null != height) {
                            float weightF = Float.parseFloat(weight.toString());
                            float hightF = Float.parseFloat(height.toString());
                            if (hightF > 0) {
                                float api = hightF / 100;
                                float mbi = weightF / (api * api);
                                BigDecimal b = new BigDecimal(mbi);
                                float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();  //年龄别体重指数   体重指数= 体重/身高^2(单位m)
                                map.put("xDate", xdate);
                                map.put("yDate", f1);
                                map.put("flag", 1);

                                try {
                                    paramMap.put("values", f1);
                                    paramMap.put("type", Constants.DEVELOPPROJECT_AGEFORWH);
                                    List<Map<String, Object>> list = getGrowthResult(ageType, paramMap, patient);
                                    map.put("result", JSON.toJSONString(list));
                                } catch (Exception e) {
                                    logger.error("计算百分位有误", e);
                                }
                                wfas.add(map);
                            }
                        }

                        paramMap.remove("values");
                        paramMap.remove("type");
                    }
                }

                if (!CollectionUtils.isEmpty(growthDetailsList)) {
                    for (int j = 0; j < growthDetailsList.size(); j++) {
                        growthDetailsMap = growthDetailsList.get(j);
                        map = new HashMap<String, Object>();
                        int flag = 0;//是否当前记录
                        if (StringUtils.isEmpty(type)) {
                            if (growthDetailsMap.get("growthRecordId").equals(paramMap.get("growthRecordId"))) {
                                flag = 1;//当前记录
                                endTime = (testdate.getTime() - birthLong) / (1000 * 60 * 60 * 24);
                                xdate = endTime / timeUnitLong;
                            } else {
                                //
                                if (testTime.equals(growthDetailsMap.get("testTime"))) {//删除日期和当前记录相等的
                                    continue;
                                }
                                testTimeHis = growthDetailsMap.get("testTime");//计算每次记录的 X轴
                                endTimeHis = (DateUtil.getDate_8(testTimeHis.toString()).getTime() - birthLong) / (1000 * 60 * 60 * 24);
                                xdate = endTimeHis / timeUnitLong;//小于0 不用处理
                            }
                        } else {// 上传记录日期和查询出有重复的 日期的 去掉查出来的记录
                            if (testTime.equals(growthDetailsMap.get("testTime").toString())) {
                                continue;
                            }
                            testTimeHis = growthDetailsMap.get("testTime");
                            endTimeHis = (DateUtil.getDate_8(testTimeHis.toString()).getTime() - birthLong) / (1000 * 60 * 60 * 24);
                            xdate = endTimeHis / timeUnitLong;
                        }

                        map.put("xDate", xdate);
                        map.put("flag", flag);
                        map.put("yDate", growthDetailsMap.get("weight"));

                        String result = "";

                        if (Constants.GROWTH_AGE_TYPE_ACTUAL.equals(ageType)) {//按实际年龄计算  重新计算年龄
                            growthDetailsMap.put("result", growthDetailsMap.get("actualResult"));
                        }
                        if (null != growthDetailsMap.get("result")) {
                            try {
                                result = JSON.parseObject(growthDetailsMap.get("result").toString()).getString("weightResult");
                                map.put("result", result);
                            } catch (Exception e) {
                                logger.error("生长发育曲线 获取记录结果error", e);
                            }
                        }
                        weights.add(map);

                        map = new HashMap<String, Object>();
                        map.put("xDate", xdate);
                        map.put("yDate", growthDetailsMap.get("hight"));
                        map.put("flag", flag);

                        if (null != growthDetailsMap.get("result")) {
                            try {
                                result = JSON.parseObject(growthDetailsMap.get("result").toString()).getString("heightResult");
                                map.put("result", result);
                            } catch (Exception e) {
                                logger.error("生长发育曲线 获取记录结果error", e);
                            }
                        }
                        hights.add(map);

                        map = new HashMap<String, Object>();
                        map.put("xDate", xdate);
                        map.put("yDate", growthDetailsMap.get("headCircumference"));
                        map.put("flag", flag);

                        if (null != growthDetailsMap.get("result")) {
                            try {
                                result = JSON.parseObject(growthDetailsMap.get("result").toString()).getString("headtResult");
                                map.put("result", result);
                            } catch (Exception e) {
                                logger.error("生长发育曲线 获取记录结果error", e);
                            }
                        }
                        heads.add(map);

                        map = new HashMap<String, Object>();
                        if (null != growthDetailsMap.get("weight") && null != growthDetailsMap.get("hight")) {
                            float weight = Float.parseFloat(growthDetailsMap.get("weight").toString());
                            float hight = Float.parseFloat(growthDetailsMap.get("hight").toString());
                            if (hight > 0) {
                                float api = hight / 100;
                                float mbi = weight / (api * api);
                                BigDecimal b = new BigDecimal(mbi);
                                float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();  //年龄别体重指数   体重指数= 体重/身高^2(单位m)
                                map.put("xDate", xdate);
                                map.put("yDate", f1);
                                map.put("flag", flag);
                                wfas.add(map);
                            }
                        }

                        map = new HashMap<String, Object>();
                        if (null != growthDetailsMap.get("hight")) {
                            double i = Double.parseDouble(growthDetailsMap.get("hight").toString());
                            if (i * 10 % 10 == 1 || i * 10 % 10 == 6) i -= 0.1;
                            if (i * 10 % 10 == 2 || i * 10 % 10 == 7) i -= 0.2;
                            if (i * 10 % 10 == 3 || i * 10 % 10 == 8) i += 0.2;
                            if (i * 10 % 10 == 4 || i * 10 % 10 == 9) i += 0.1;
                            map.put("yDate", growthDetailsMap.get("weight"));
                            map.put("xDate", i);
                            map.put("flag", flag);
                            hfws.add(map);
                        }
                    }
                }

                weightMap.put("growthrecord", weights);
                lengthForWttMap.put("growthrecord", hfws);
                ageForWtMap.put("growthrecord", wfas);
                lengthMap.put("growthrecord", hights);
                headMap.put("growthrecord", heads);
                //先从缓存查询  没有再查询数据库
                Jedis jedis = null;
                Map<String, Object> weightMapSD = null;
                Map<String, Object> lengthMapSD = null;
                Map<String, Object> headMapSD = null;
                Map<String, Object> lengthForWttMapSD = null;
                Map<String, Object> ageForWtMapSD = null;
                try {
                    jedis = jedisPool.getResource();
                    jedis.select(Constants.REDIS_DB_INDEX_EVALUATION);
                    String str = "";

                    if (patient.getGender().equals(Constants.GENDER_FOR_FEMALE)) {
                        redisKey += ":GIRLS";
                        redisKeyLfW += ":GIRLS";
                    } else {
                        redisKey += ":BOYS";
                        redisKeyLfW += ":BOYS";
                    }
                    str = jedis.get(Constants.GROWTH_KEY_WEIGHT + redisKey);
                    if (!StringUtils.isEmpty(str)) {
                        weightMapSD = JSONObject.parseObject(str);
                    }
                    str = jedis.get(Constants.GROWTH_KEY_LENGTH + redisKey);
                    if (!StringUtils.isEmpty(str)) {
                        lengthMapSD = JSONObject.parseObject(str);
                    }

                    str = jedis.get(Constants.GROWTH_KEY_HEAD + redisKey);
                    if (!StringUtils.isEmpty(str)) {
                        headMapSD = JSONObject.parseObject(str);
                    }

                    str = jedis.get(Constants.GROWTH_KEY_BMI + redisKey);
                    if (!StringUtils.isEmpty(str)) {
                        ageForWtMapSD = JSONObject.parseObject(str);
                    }

                    str = jedis.get(Constants.GROWTH_KEY_WEIGHT_FOR_LENGTH + redisKeyLfW);
                    if (!StringUtils.isEmpty(str)) {
                        lengthForWttMapSD = JSONObject.parseObject(str);
                    }

                    if (lengthForWttMapSD == null || ageForWtMapSD == null || headMapSD == null || lengthMapSD == null || weightMapSD == null) {
                        //有一个为空 则从数据库查询
                        weightMapSD = new HashMap<String, Object>();
                        lengthMapSD = new HashMap<String, Object>();
                        headMapSD = new HashMap<String, Object>();
                        lengthForWttMapSD = new HashMap<String, Object>();
                        ageForWtMapSD = new HashMap<String, Object>();

                        List<Map<String, Object>> standardList = new ArrayList<Map<String, Object>>();
                        Map<String, Object> standardParam = new HashMap<String, Object>();

                        if (timeUnit.equals("周")) {
                            standardParam.put("age", 182);  //30.4*6 天数据
                        } else if (timeUnit.equals("月")) {
                            standardParam.put("age", 730);    // 365*2 =730天
                        } else if (timeUnit.equals("年")) {
                            standardParam.put("age", 1855); //365*5 =  1855
                        }

                        standardParam.put("gender", patient.getGender());
                        standardParam.put("standardId", Constants.WHO_STANDARD_ID);

                        standardParam.put("standardType", Constants.WHO_STANDARD_TYPE_PERCENT);
                        if (Constants.GROWTH_SCORE_ZSCORE.equals(scoreType)) {//如果计算zscore 则传zscore类型
                            standardParam.put("standardType", Constants.WHO_STANDARD_TYPE_SCORE);
                        }

                        standardList = familyReportDAO.selectStandardList(standardParam);
                        if (CollectionUtils.isEmpty(standardList)) {
                            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_GROWTHS_STANDARD_WHO_NOT_EXIST, "生长发育WHO标准数据不存在");
                        }

                        //
                        //当小于两岁时 需要查询身高别体重
                        standardParam = new HashMap<String, Object>();
                        standardParam.put("developProjectId", Constants.DEVELOPPROJECT_LENGTHFORWEIGHT);
                        standardParam.put("gender", patient.getGender());
                        standardParam.put("standardId", Constants.WHO_STANDARD_ID);
                        standardParam.put("standardType", Constants.WHO_STANDARD_TYPE_PERCENT);
                        if (Constants.GROWTH_SCORE_ZSCORE.equals(scoreType)) {//如果计算zscore 则传zscore类型
                            standardParam.put("standardType", Constants.WHO_STANDARD_TYPE_SCORE);
                        }
                        List<Map<String, Object>> lengthStandardList = familyReportDAO.selectStandardwfhList(standardParam);

                        //数据处理
                        processGrowthData(flagType, scoreType, patient, timeUnit,
                                weightMapSD, lengthMapSD, headMapSD,
                                lengthForWttMapSD, ageForWtMapSD, standardList, lengthStandardList);

                        jedis.set(Constants.GROWTH_KEY_WEIGHT + redisKey, JSONObject.toJSONString(weightMapSD));
                        jedis.set(Constants.GROWTH_KEY_LENGTH + redisKey, JSONObject.toJSONString(lengthMapSD));
                        jedis.set(Constants.GROWTH_KEY_HEAD + redisKey, JSONObject.toJSONString(headMapSD));
                        jedis.set(Constants.GROWTH_KEY_BMI + redisKey, JSONObject.toJSONString(ageForWtMapSD));
                        jedis.set(Constants.GROWTH_KEY_WEIGHT_FOR_LENGTH + redisKeyLfW, JSONObject.toJSONString(lengthForWttMapSD));
                    }
                } catch (JedisConnectionException jex) {
                    logger.error("redis连接异常..." + jex.getMessage());
                    throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_REDIS_CONNECT_ERROR, "Redis缓存连接失败!"));
                } finally {
                    if (null != jedis) {
                        try {
                            jedis.close();
                            logger.warn("close redis connection...");
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_REDIS_CONNECT_CLOSE_FAILED,
                                    "Redis缓存关闭失败!"));
                        }
                    }
                }

                weightMap.putAll(weightMapSD);
                lengthMap.putAll(lengthMapSD);
                headMap.putAll(headMapSD);
                lengthForWttMap.putAll(lengthForWttMapSD);
                ageForWtMap.putAll(ageForWtMapSD);

                Map<String, Object> rspMap = null;
                if (!StringUtils.isEmpty(type) && StringUtils.isEmpty(valueFlag)) {
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        rspMap = new HashMap<String, Object>();
                        rspMap.put("curvedata", headMap);
                        rspMap.put("type", Constants.DEVELOPPROJECT_HEAD);
                        rspMap.put("standardName", Constants.WHO_STANDARD_NAME);
                        rsp.add(rspMap);
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        rspMap = new HashMap<String, Object>();
                        rspMap.put("curvedata", weightMap);
                        rspMap.put("type", Constants.DEVELOPPROJECT_WEIGHT);
                        rspMap.put("standardName", Constants.WHO_STANDARD_NAME);
                        rsp.add(rspMap);
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        rspMap = new HashMap<String, Object>();
                        rspMap.put("curvedata", lengthMap);
                        rspMap.put("type", Constants.DEVELOPPROJECT_LENGTH);
                        rspMap.put("standardName", Constants.WHO_STANDARD_NAME);
                        rsp.add(rspMap);
                    }
                } else {
                    rspMap = new HashMap<String, Object>();
                    rspMap.put("curvedata", weightMap);
                    rspMap.put("type", Constants.DEVELOPPROJECT_WEIGHT);
                    rspMap.put("standardName", Constants.WHO_STANDARD_NAME);
                    rsp.add(rspMap);

                    rspMap = new HashMap<String, Object>();
                    rspMap.put("curvedata", lengthMap);
                    rspMap.put("type", Constants.DEVELOPPROJECT_LENGTH);
                    rspMap.put("standardName", Constants.WHO_STANDARD_NAME);
                    rsp.add(rspMap);

                    rspMap = new HashMap<String, Object>();
                    rspMap.put("curvedata", headMap);
                    rspMap.put("type", Constants.DEVELOPPROJECT_HEAD);
                    rspMap.put("standardName", Constants.WHO_STANDARD_NAME);
                    rsp.add(rspMap);

                    if ((float) endTime / yearDay <= 2) { //2岁以内
                        rspMap = new HashMap<String, Object>();
                        rspMap.put("curvedata", lengthForWttMap);
                        rspMap.put("type", Constants.DEVELOPPROJECT_LENGTHFORWEIGHT);
                        rspMap.put("standardName", Constants.WHO_STANDARD_NAME);
                        rsp.add(rspMap);
                    } else {
                        rspMap = new HashMap<String, Object>();
                        rspMap.put("curvedata", ageForWtMap);
                        rspMap.put("type", Constants.DEVELOPPROJECT_AGEFORWH);
                        rspMap.put("standardName", Constants.WHO_STANDARD_NAME);
                        rsp.add(rspMap);
                    }
                }
            } else {
                rsp = getGrowthFiveOverCurvedata(paramMap, patient, growthDetailsList, testTime);
            }
            curaDataMap.put("curveType", Constants.GROWTH_CURVEDATA_LINES);
        } else { // 纠正年龄 为负 则调用fenton曲线
            rsp = getGrowthFentonCurvedata(paramMap, patient, growthDetailsList, testTime);
            curaDataMap.put("curveType", Constants.FENTON_CURVEDATA_LINES);
        }

        curaDataMap.put("curvadataList", rsp);
        curaDataMap.put("ageType", ageType);
        curaDataMap.put("scoreType", scoreType);
        return curaDataMap;
    }

    //生长发育数据处理方法
    private void processGrowthFiveData(String flagType, String scoreType, Patient patient, Map<String, Object> weightMapSD,
                                       Map<String, Object> lengthMapSD, Map<String, Object> bmiMapSD, List<Map<String, Object>> standardList) throws Exception {
        Map<String, Object> temp = null;
        ArrayList<Float> SD2neg = new ArrayList<>();
        ArrayList<Float> SD1neg = new ArrayList<>();
        ArrayList<Float> SD3neg = new ArrayList<>();
        ArrayList<Float> SD4neg = new ArrayList<>();
        ArrayList<Float> SD0 = new ArrayList<>();
        ArrayList<Float> SD1 = new ArrayList<>();
        ArrayList<Float> SD2 = new ArrayList<>();
        ArrayList<Float> SD3 = new ArrayList<>();
        ArrayList<Float> SD4 = new ArrayList<>();
        ArrayList<Float> P15 = new ArrayList<>();
        ArrayList<Float> P85 = new ArrayList<>();

        ArrayList<Float> weightSD2neg = new ArrayList<>();
        ArrayList<Float> weightSD1neg = new ArrayList<>();
        ArrayList<Float> weightSD3neg = new ArrayList<>();
        ArrayList<Float> weightSD4neg = new ArrayList<>();
        ArrayList<Float> weightSD0 = new ArrayList<>();
        ArrayList<Float> weightSD1 = new ArrayList<>();
        ArrayList<Float> weightSD2 = new ArrayList<>();
        ArrayList<Float> weightSD3 = new ArrayList<>();
        ArrayList<Float> weightSD4 = new ArrayList<>();
        ArrayList<Float> weightP15 = new ArrayList<>();
        ArrayList<Float> weightP85 = new ArrayList<>();

        ArrayList<Float> bmiSD2neg = new ArrayList<>();
        ArrayList<Float> bmiSD1neg = new ArrayList<>();
        ArrayList<Float> bmiSD3neg = new ArrayList<>();
        ArrayList<Float> bmiSD4neg = new ArrayList<>();
        ArrayList<Float> bmiSD0 = new ArrayList<>();
        ArrayList<Float> bmiSD1 = new ArrayList<>();
        ArrayList<Float> bmiSD2 = new ArrayList<>();
        ArrayList<Float> bmiSD3 = new ArrayList<>();
        ArrayList<Float> bmiSD4 = new ArrayList<>();
        ArrayList<Float> bmiP15 = new ArrayList<>();
        ArrayList<Float> bmiP85 = new ArrayList<>();

        for (int i = 0; i < standardList.size(); i++) {
            temp = standardList.get(i);
            if (Constants.DEVELOPPROJECT_LENGTH.equals(temp.get("developProject_id"))) {
                SD2neg.add(Float.parseFloat(temp.get("SD2NEG").toString()));
                SD1neg.add(Float.parseFloat(temp.get("SD1NEG").toString()));
                SD3neg.add(Float.parseFloat(temp.get("SD3NEG").toString()));
                SD4neg.add(Float.parseFloat(temp.get("SD4NEG").toString()));
                SD0.add(Float.parseFloat(temp.get("SD0").toString()));
                SD1.add(Float.parseFloat(temp.get("SD1").toString()));
                SD2.add(Float.parseFloat(temp.get("SD2").toString()));
                SD3.add(Float.parseFloat(temp.get("SD3").toString()));
                SD4.add(Float.parseFloat(temp.get("SD4").toString()));
                if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                    P15.add(Float.parseFloat(temp.get("P15").toString()));
                    P85.add(Float.parseFloat(temp.get("P85").toString()));
                }
            } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(temp.get("developProject_id"))) {
                weightSD2neg.add(Float.parseFloat(temp.get("SD2NEG").toString()));
                weightSD1neg.add(Float.parseFloat(temp.get("SD1NEG").toString()));
                weightSD3neg.add(Float.parseFloat(temp.get("SD3NEG").toString()));
                weightSD4neg.add(Float.parseFloat(temp.get("SD4NEG").toString()));
                weightSD0.add(Float.parseFloat(temp.get("SD0").toString()));
                weightSD1.add(Float.parseFloat(temp.get("SD1").toString()));
                weightSD2.add(Float.parseFloat(temp.get("SD2").toString()));
                weightSD3.add(Float.parseFloat(temp.get("SD3").toString()));
                weightSD4.add(Float.parseFloat(temp.get("SD4").toString()));
                if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                    weightP15.add(Float.parseFloat(temp.get("P15").toString()));
                    weightP85.add(Float.parseFloat(temp.get("P85").toString()));
                }
            } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(temp.get("developProject_id"))) {
                bmiSD2neg.add(Float.parseFloat(temp.get("SD2NEG").toString()));
                bmiSD1neg.add(Float.parseFloat(temp.get("SD1NEG").toString()));
                bmiSD3neg.add(Float.parseFloat(temp.get("SD3NEG").toString()));
                bmiSD4neg.add(Float.parseFloat(temp.get("SD4NEG").toString()));
                bmiSD0.add(Float.parseFloat(temp.get("SD0").toString()));
                bmiSD1.add(Float.parseFloat(temp.get("SD1").toString()));
                bmiSD2.add(Float.parseFloat(temp.get("SD2").toString()));
                bmiSD3.add(Float.parseFloat(temp.get("SD3").toString()));
                bmiSD4.add(Float.parseFloat(temp.get("SD4").toString()));
                if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                    bmiP15.add(Float.parseFloat(temp.get("P15").toString()));
                    bmiP85.add(Float.parseFloat(temp.get("P85").toString()));
                }
            }
        }

        if (Constants.NUMBER_TYPE_FIVE_CURVES.equals(flagType)) {//5条
            weightMapSD.put("yMax", Math.round(Collections.max(weightSD3)) + 1);  //
            lengthMapSD.put("yMax", Math.round(Collections.max(SD3)) + 1);
            bmiMapSD.put("yMax", Math.round(Collections.max(bmiSD3)) + 1);
            weightMapSD.put("yMin", Math.round(Collections.min(weightSD3neg)) - 1);
            bmiMapSD.put("yMin", Math.round(Collections.min(bmiSD3neg)) - 1);
            lengthMapSD.put("yMin", Math.round(Collections.min(SD3neg)) - 1);
        } else if (Constants.NUMBER_TYPE_SEVEN_CURVES.equals(flagType)) {//9条
            weightMapSD.put("yMax", Math.round(Collections.max(weightSD4)) + 1);  //
            lengthMapSD.put("yMax", Math.round(Collections.max(SD4)) + 1);
            bmiMapSD.put("yMax", Math.round(Collections.max(bmiSD4)) + 1);
            weightMapSD.put("yMin", Math.round(Collections.min(weightSD4neg)) - 1);
            bmiMapSD.put("yMin", Math.round(Collections.min(bmiSD3neg)) - 1);
            lengthMapSD.put("yMin", Math.round(Collections.min(SD4neg)) - 1);
        } else {
            weightMapSD.put("yMax", Math.round(Collections.max(weightSD3)) + 1);  //
            lengthMapSD.put("yMax", Math.round(Collections.max(SD3)) + 1);
            bmiMapSD.put("yMax", Math.round(Collections.max(bmiSD3)) + 1);
            weightMapSD.put("yMin", Math.round(Collections.min(weightSD3neg)) - 1);
            bmiMapSD.put("yMin", Math.round(Collections.min(bmiSD3neg)) - 1);
            lengthMapSD.put("yMin", Math.round(Collections.min(SD3neg)) - 1);
        }

        //获取9条曲线数据  //展示7条
        weightMapSD.put("SD0", weightSD0);
        weightMapSD.put("SD1", weightSD1);
        weightMapSD.put("SD2", weightSD2);
        weightMapSD.put("SD3", weightSD3);
        weightMapSD.put("SD4", weightSD4);
        weightMapSD.put("SD1eng", weightSD1neg);
        weightMapSD.put("SD2eng", weightSD2neg);
        weightMapSD.put("SD3eng", weightSD3neg);
        weightMapSD.put("SD4eng", weightSD4neg);
        weightMapSD.put("P15", weightP15);
        weightMapSD.put("P85", weightP85);

        lengthMapSD.put("SD0", SD0);
        lengthMapSD.put("SD1", SD1);
        lengthMapSD.put("SD2", SD2);
        lengthMapSD.put("SD3", SD3);
        lengthMapSD.put("SD4", SD4);
        lengthMapSD.put("SD1eng", SD1neg);
        lengthMapSD.put("SD2eng", SD2neg);
        lengthMapSD.put("SD3eng", SD3neg);
        lengthMapSD.put("SD4eng", SD4neg);
        lengthMapSD.put("P15", P15);
        lengthMapSD.put("P85", P85);

        bmiMapSD.put("SD0", bmiSD0);
        bmiMapSD.put("SD1", bmiSD1);
        bmiMapSD.put("SD2", bmiSD2);
        bmiMapSD.put("SD3", bmiSD3);
        bmiMapSD.put("SD4", bmiSD4);
        bmiMapSD.put("SD1eng", bmiSD1neg);
        bmiMapSD.put("SD2eng", bmiSD2neg);
        bmiMapSD.put("SD3eng", bmiSD3neg);
        bmiMapSD.put("SD4eng", bmiSD4neg);
        bmiMapSD.put("P15", bmiP15);
        bmiMapSD.put("P85", bmiP85);
    }

    //生长发育数据处理方法
    private void processGrowthData(String flagType, String scoreType,
                                   Patient patient, String timeUnit, Map<String, Object> weightMapSD,
                                   Map<String, Object> lengthMapSD, Map<String, Object> headMapSD,
                                   Map<String, Object> lengthForWttMapSD,
                                   Map<String, Object> ageForWtMapSD,
                                   List<Map<String, Object>> standardList, List<Map<String, Object>> lengthStandardList) throws Exception {
        Map<String, Object> temp = null;
        ArrayList<Float> SD2neg = new ArrayList<>();
        ArrayList<Float> SD1neg = new ArrayList<>();
        ArrayList<Float> SD3neg = new ArrayList<>();
        ArrayList<Float> SD4neg = new ArrayList<>();
        ArrayList<Float> SD0 = new ArrayList<>();
        ArrayList<Float> SD1 = new ArrayList<>();
        ArrayList<Float> SD2 = new ArrayList<>();
        ArrayList<Float> SD3 = new ArrayList<>();
        ArrayList<Float> SD4 = new ArrayList<>();
        ArrayList<Float> P15 = new ArrayList<>();
        ArrayList<Float> P85 = new ArrayList<>();

        ArrayList<Float> weightSD2neg = new ArrayList<>();
        ArrayList<Float> weightSD1neg = new ArrayList<>();
        ArrayList<Float> weightSD3neg = new ArrayList<>();
        ArrayList<Float> weightSD4neg = new ArrayList<>();
        ArrayList<Float> weightSD0 = new ArrayList<>();
        ArrayList<Float> weightSD1 = new ArrayList<>();
        ArrayList<Float> weightSD2 = new ArrayList<>();
        ArrayList<Float> weightSD3 = new ArrayList<>();
        ArrayList<Float> weightSD4 = new ArrayList<>();
        ArrayList<Float> weightP15 = new ArrayList<>();
        ArrayList<Float> weightP85 = new ArrayList<>();

        ArrayList<Float> headSD2neg = new ArrayList<>();
        ArrayList<Float> headSD1neg = new ArrayList<>();
        ArrayList<Float> headSD3neg = new ArrayList<>();
        ArrayList<Float> headSD4neg = new ArrayList<>();
        ArrayList<Float> headSD0 = new ArrayList<>();
        ArrayList<Float> headSD1 = new ArrayList<>();
        ArrayList<Float> headSD2 = new ArrayList<>();
        ArrayList<Float> headSD3 = new ArrayList<>();
        ArrayList<Float> headSD4 = new ArrayList<>();
        ArrayList<Float> headP15 = new ArrayList<>();
        ArrayList<Float> headP85 = new ArrayList<>();

        ArrayList<Float> whSD2neg = new ArrayList<>();
        ArrayList<Float> whSD1neg = new ArrayList<>();
        ArrayList<Float> whSD3neg = new ArrayList<>();
        ArrayList<Float> whSD4neg = new ArrayList<>();
        ArrayList<Float> whSD0 = new ArrayList<>();
        ArrayList<Float> whSD1 = new ArrayList<>();
        ArrayList<Float> whSD2 = new ArrayList<>();
        ArrayList<Float> whSD3 = new ArrayList<>();
        ArrayList<Float> whSD4 = new ArrayList<>();
        ArrayList<Float> whP15 = new ArrayList<>();
        ArrayList<Float> whP85 = new ArrayList<>();

        ArrayList<Float> waSD2neg = new ArrayList<>();
        ArrayList<Float> waSD1neg = new ArrayList<>();
        ArrayList<Float> waSD3neg = new ArrayList<>();
        ArrayList<Float> waSD4neg = new ArrayList<>();
        ArrayList<Float> waSD0 = new ArrayList<>();
        ArrayList<Float> waSD1 = new ArrayList<>();
        ArrayList<Float> waSD2 = new ArrayList<>();
        ArrayList<Float> waSD3 = new ArrayList<>();
        ArrayList<Float> waSD4 = new ArrayList<>();
        ArrayList<Float> waP15 = new ArrayList<>();
        ArrayList<Float> waP85 = new ArrayList<>();

        for (int i = 0; i < standardList.size(); i++) {
            temp = standardList.get(i);
            //
            long age = Long.parseLong(temp.get("age").toString());
            if (timeUnit.equals("周")) { //180天  取90天数据
                if (age % 2 == 0) {
                } else {
                    continue;
                }
            } else if (timeUnit.equals("月")) { //730
                if (age % 8 == 0) {
                } else {
                    continue;
                }
            } else if (timeUnit.equals("年")) {//1855
                if (age % 18 == 0) {
                } else {
                    continue;
                }
            }
            if (Constants.DEVELOPPROJECT_HEAD.equals(temp.get("developProject_id"))) {
                headSD2neg.add(Float.parseFloat(temp.get("SD2NEG").toString()));
                headSD1neg.add(Float.parseFloat(temp.get("SD1NEG").toString()));
                headSD3neg.add(Float.parseFloat(temp.get("SD3NEG").toString()));
                headSD4neg.add(Float.parseFloat(temp.get("SD4NEG").toString()));
                headSD0.add(Float.parseFloat(temp.get("SD0").toString()));
                headSD1.add(Float.parseFloat(temp.get("SD1").toString()));
                headSD2.add(Float.parseFloat(temp.get("SD2").toString()));
                headSD3.add(Float.parseFloat(temp.get("SD3").toString()));
                headSD4.add(Float.parseFloat(temp.get("SD4").toString()));
                if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                    headP15.add(Float.parseFloat(temp.get("P15").toString()));
                    headP85.add(Float.parseFloat(temp.get("P85").toString()));
                }
            } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(temp.get("developProject_id"))) {
                waSD2neg.add(Float.parseFloat(temp.get("SD2NEG").toString()));
                waSD1neg.add(Float.parseFloat(temp.get("SD1NEG").toString()));
                waSD3neg.add(Float.parseFloat(temp.get("SD3NEG").toString()));
                waSD4neg.add(Float.parseFloat(temp.get("SD4NEG").toString()));
                waSD0.add(Float.parseFloat(temp.get("SD0").toString()));
                waSD1.add(Float.parseFloat(temp.get("SD1").toString()));
                waSD2.add(Float.parseFloat(temp.get("SD2").toString()));
                waSD3.add(Float.parseFloat(temp.get("SD3").toString()));
                waSD4.add(Float.parseFloat(temp.get("SD4").toString()));
                if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                    waP15.add(Float.parseFloat(temp.get("P15").toString()));
                    waP85.add(Float.parseFloat(temp.get("P85").toString()));
                }
            } else if (Constants.DEVELOPPROJECT_LENGTH.equals(temp.get("developProject_id"))) {
                SD2neg.add(Float.parseFloat(temp.get("SD2NEG").toString()));
                SD1neg.add(Float.parseFloat(temp.get("SD1NEG").toString()));
                SD3neg.add(Float.parseFloat(temp.get("SD3NEG").toString()));
                SD4neg.add(Float.parseFloat(temp.get("SD4NEG").toString()));
                SD0.add(Float.parseFloat(temp.get("SD0").toString()));
                SD1.add(Float.parseFloat(temp.get("SD1").toString()));
                SD2.add(Float.parseFloat(temp.get("SD2").toString()));
                SD3.add(Float.parseFloat(temp.get("SD3").toString()));
                SD4.add(Float.parseFloat(temp.get("SD4").toString()));
                if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                    P15.add(Float.parseFloat(temp.get("P15").toString()));
                    P85.add(Float.parseFloat(temp.get("P85").toString()));
                }
            } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(temp.get("developProject_id"))) {
                weightSD2neg.add(Float.parseFloat(temp.get("SD2NEG").toString()));
                weightSD1neg.add(Float.parseFloat(temp.get("SD1NEG").toString()));
                weightSD3neg.add(Float.parseFloat(temp.get("SD3NEG").toString()));
                weightSD4neg.add(Float.parseFloat(temp.get("SD4NEG").toString()));
                weightSD0.add(Float.parseFloat(temp.get("SD0").toString()));
                weightSD1.add(Float.parseFloat(temp.get("SD1").toString()));
                weightSD2.add(Float.parseFloat(temp.get("SD2").toString()));
                weightSD3.add(Float.parseFloat(temp.get("SD3").toString()));
                weightSD4.add(Float.parseFloat(temp.get("SD4").toString()));
                if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                    weightP15.add(Float.parseFloat(temp.get("P15").toString()));
                    weightP85.add(Float.parseFloat(temp.get("P85").toString()));
                }
            }
        }

        if (!CollectionUtils.isEmpty(lengthStandardList)) {
            for (int i = 0; i < lengthStandardList.size(); i++) {
                temp = lengthStandardList.get(i);
                if (Constants.DEVELOPPROJECT_LENGTHFORWEIGHT.equals(temp.get("developProject_id"))) {
                    //
                    if (null != temp.get("length")) {
                        float length = Float.parseFloat(temp.get("length").toString());
                        if (length * 10 % 10 != 0 && length * 10 % 10 != 0.0) {//展示长度为 1.0倍数的
                            continue;
                        }
                    }
                    whSD2neg.add(Float.parseFloat(temp.get("SD2NEG").toString()));
                    whSD1neg.add(Float.parseFloat(temp.get("SD1NEG").toString()));
                    whSD3neg.add(Float.parseFloat(temp.get("SD3NEG").toString()));
                    whSD4neg.add(Float.parseFloat(temp.get("SD4NEG").toString()));
                    whSD0.add(Float.parseFloat(temp.get("SD0").toString()));
                    whSD1.add(Float.parseFloat(temp.get("SD1").toString()));
                    whSD2.add(Float.parseFloat(temp.get("SD2").toString()));
                    whSD3.add(Float.parseFloat(temp.get("SD3").toString()));
                    whSD4.add(Float.parseFloat(temp.get("SD4").toString()));
                    if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                        whP15.add(Float.parseFloat(temp.get("P15").toString()));
                        whP85.add(Float.parseFloat(temp.get("P85").toString()));
                    }
                }
            }
        } else {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_GROWTHS_STANDARD_WHO_NOT_EXIST, "身高别体重数据不存在");
        }

        if (Constants.NUMBER_TYPE_FIVE_CURVES.equals(flagType)) {//5条
            weightMapSD.put("yMax", Math.round(Collections.max(weightSD3)) + 1);  //
            ageForWtMapSD.put("yMax", Math.round(Collections.max(waSD3)) + 1);
            headMapSD.put("yMax", Math.round(Collections.max(headSD3)) + 1);
            lengthMapSD.put("yMax", Math.round(Collections.max(SD3)) + 1);
            lengthForWttMapSD.put("yMax", Math.round(Collections.max(whSD3)) + 1);
            lengthForWttMapSD.put("yMin", Math.round(Collections.min(whSD3neg)) - 1);
            weightMapSD.put("yMin", Math.round(Collections.min(weightSD3neg)) - 1);
            ageForWtMapSD.put("yMin", Math.round(Collections.min(waSD3neg)) - 1);
            headMapSD.put("yMin", Math.round(Collections.min(headSD3neg)) - 1);
            lengthMapSD.put("yMin", Math.round(Collections.min(SD3neg)) - 1);
        } else if (Constants.NUMBER_TYPE_SEVEN_CURVES.equals(flagType)) {//9条
            weightMapSD.put("yMax", Math.round(Collections.max(weightSD4)) + 1);  //
            ageForWtMapSD.put("yMax", Math.round(Collections.max(waSD4)) + 1);
            headMapSD.put("yMax", Math.round(Collections.max(headSD4)) + 1);
            lengthMapSD.put("yMax", Math.round(Collections.max(SD4)) + 1);
            lengthForWttMapSD.put("yMax", Math.round(Collections.max(whSD4)) + 1);
            lengthForWttMapSD.put("yMin", Math.round(Collections.min(whSD4neg)) - 1);
            weightMapSD.put("yMin", Math.round(Collections.min(weightSD4neg)) - 1);
            ageForWtMapSD.put("yMin", Math.round(Collections.min(waSD4neg)) - 1);
            headMapSD.put("yMin", Math.round(Collections.min(headSD4neg)) - 1);
            lengthMapSD.put("yMin", Math.round(Collections.min(SD4neg)) - 1);
        } else {
            weightMapSD.put("yMax", Math.round(Collections.max(weightSD3)) + 1);  //
            ageForWtMapSD.put("yMax", Math.round(Collections.max(waSD3)) + 1);
            headMapSD.put("yMax", Math.round(Collections.max(headSD3)) + 1);
            lengthMapSD.put("yMax", Math.round(Collections.max(SD3)) + 1);
            lengthForWttMapSD.put("yMax", Math.round(Collections.max(whSD3)) + 1);
            lengthForWttMapSD.put("yMin", Math.round(Collections.min(whSD3neg)) - 1);
            weightMapSD.put("yMin", Math.round(Collections.min(weightSD3neg)) - 1);
            ageForWtMapSD.put("yMin", Math.round(Collections.min(waSD3neg)) - 1);
            headMapSD.put("yMin", Math.round(Collections.min(headSD3neg)) - 1);
            lengthMapSD.put("yMin", Math.round(Collections.min(SD3neg)) - 1);
        }

        //获取9条曲线数据  //展示7条
        weightMapSD.put("SD0", weightSD0);
        weightMapSD.put("SD1", weightSD1);
        weightMapSD.put("SD2", weightSD2);
        weightMapSD.put("SD3", weightSD3);
        weightMapSD.put("SD4", weightSD4);
        weightMapSD.put("SD1eng", weightSD1neg);
        weightMapSD.put("SD2eng", weightSD2neg);
        weightMapSD.put("SD3eng", weightSD3neg);
        weightMapSD.put("SD4eng", weightSD4neg);
        weightMapSD.put("P15", weightP15);
        weightMapSD.put("P85", weightP85);

        lengthMapSD.put("SD0", SD0);
        lengthMapSD.put("SD1", SD1);
        lengthMapSD.put("SD2", SD2);
        lengthMapSD.put("SD3", SD3);
        lengthMapSD.put("SD4", SD4);
        lengthMapSD.put("SD1eng", SD1neg);
        lengthMapSD.put("SD2eng", SD2neg);
        lengthMapSD.put("SD3eng", SD3neg);
        lengthMapSD.put("SD4eng", SD4neg);
        lengthMapSD.put("P15", P15);
        lengthMapSD.put("P85", P85);

        ageForWtMapSD.put("SD0", waSD0);
        ageForWtMapSD.put("SD1", waSD1);
        ageForWtMapSD.put("SD2", waSD2);
        ageForWtMapSD.put("SD3", waSD3);
        ageForWtMapSD.put("SD4", waSD4);
        ageForWtMapSD.put("SD1eng", waSD1neg);
        ageForWtMapSD.put("SD2eng", waSD2neg);
        ageForWtMapSD.put("SD3eng", waSD3neg);
        ageForWtMapSD.put("SD4eng", waSD4neg);
        ageForWtMapSD.put("P15", waP15);
        ageForWtMapSD.put("P85", waP85);

        headMapSD.put("SD0", headSD0);
        headMapSD.put("SD1", headSD1);
        headMapSD.put("SD2", headSD2);
        headMapSD.put("SD3", headSD3);
        headMapSD.put("SD4", headSD4);
        headMapSD.put("SD1eng", headSD1neg);
        headMapSD.put("SD2eng", headSD2neg);
        headMapSD.put("SD3eng", headSD3neg);
        headMapSD.put("SD4eng", headSD4neg);
        headMapSD.put("P15", headP15);
        headMapSD.put("P85", headP85);

        lengthForWttMapSD.put("SD0", whSD0);
        lengthForWttMapSD.put("SD1", whSD1);
        lengthForWttMapSD.put("SD2", whSD2);
        lengthForWttMapSD.put("SD3", whSD3);
        lengthForWttMapSD.put("SD4", whSD4);
        lengthForWttMapSD.put("SD1eng", whSD1neg);
        lengthForWttMapSD.put("SD2eng", whSD2neg);
        lengthForWttMapSD.put("SD3eng", whSD3neg);
        lengthForWttMapSD.put("SD4eng", whSD4neg);
        lengthForWttMapSD.put("P15", whP15);
        lengthForWttMapSD.put("P85", whP85);
    }

    @SuppressWarnings("unchecked")
    @Override
    @Transactional
    public void oxygenpulserateSynchData(Map<String, Object> paramMap)
            throws Exception {
        logger.warn("in oxygenpulserateSynchData----arg==" + paramMap);
        Oxygenpulserate oxygenPulserate = (Oxygenpulserate) paramMap.get("oxygenPulserate");
        Oxygenpulserateanalysis oxygenPulserateAnalysis = (Oxygenpulserateanalysis) paramMap.get("oxygenPulserateAnalysis");
        List<Oxygenpulseratedetail> oxygenPulserateDetails = (List<Oxygenpulseratedetail>) paramMap.get("oxygenPulserateDetails");

        familyReportDAO.saveOxygenpulserateanalysis(oxygenPulserateAnalysis);
        familyReportDAO.saveOxygenpulserate(oxygenPulserate);
        familyReportDAO.saveOxygenpulseratedetail(oxygenPulserateDetails);

        logger.warn("out oxygenpulserateSynchData----arg==" + paramMap);
    }

    @SuppressWarnings("unchecked")
    @Override
    @Transactional
    public void bodyTemperatureSynchData(Map<String, Object> paramMap) throws Exception {
        logger.warn("in bodyTemperatureSynchData----arg==" + paramMap);
        BodyTemperature bodyTemperature = (BodyTemperature) paramMap.get("bodyTemperature");
        BodyTemperatureanalysis bodyTemperatureAnalysis = (BodyTemperatureanalysis) paramMap.get("bodyTemperatureanalysis");
        List<BodyTemperaturedetail> bodyTemperatureDetails = (List<BodyTemperaturedetail>) paramMap.get("bodyTemperaturedetails");

        familyReportDAO.saveBodyTemperatureanalysis(bodyTemperatureAnalysis);
        familyReportDAO.saveBodyTemperature(bodyTemperature);
        familyReportDAO.saveBodyTemperaturedetail(bodyTemperatureDetails);

        logger.warn("out bodyTemperatureSynchData----arg==" + paramMap);
    }

    @Override
    @Transactional
    public Map<String, Object> addGrowthRecordBySyn(Map<String, Object> paramMap)
            throws Exception {

        Map<String, Object> param = new HashMap<String, Object>();
        Date createTime = new Date();
        if (null == paramMap.get("testTime")) {
            paramMap.put("testTime", DateUtil.getDate_8(createTime));
        } else {
            paramMap.put("testTime", paramMap.get("testTime"));
        }

        String seq = SeqUtil.getSeqNo("18");
        paramMap.put("sourceType", "01"); //APP传入
        paramMap.put("sourceId", "bbcareapp");
        paramMap.put("createTime", DateUtil.getDateA(createTime));
//		paramMap.put("testTime",param.get("testTime"));
//		if(null == growthMap){
        paramMap.put("id", seq);


        Map<String, Object> map = new HashMap<String, Object>();
        map.put("tenantId", paramMap.get("tenantId"));
        map.put("userId", paramMap.get("userId"));
        map.put("testTime", paramMap.get("testTime"));
        Patient patient = patientdao.selectById(map);
        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "生长发育评估记录患者信息不存在");
        }
        try {
            String weight = (String) paramMap.get("weight");
            String height = (String) paramMap.get("height");
            String headCircumference = (String) paramMap.get("headCircumference");

            Map<String, List<Map<String, Object>>> actualResult = new HashMap<String, List<Map<String, Object>>>();
            Map<String, List<Map<String, Object>>> result = new HashMap<String, List<Map<String, Object>>>();

            if (!StringUtils.isEmpty(weight)) {
                map.put("values", weight);
                map.put("type", Constants.DEVELOPPROJECT_WEIGHT);
                List<Map<String, Object>> resultList = getGrowthResult(Constants.GROWTH_AGE_TYPE_CORRECT, map, patient);
                if (!CollectionUtils.isEmpty(resultList)) {
                    result.put("weightResult", resultList);
                }

                List<Map<String, Object>> actualList = getGrowthResult(Constants.GROWTH_AGE_TYPE_ACTUAL, map, patient);
                if (!CollectionUtils.isEmpty(actualList)) {
                    actualResult.put("weightResult", actualList);
                }
            }
            if (!StringUtils.isEmpty(height)) {
                map.put("values", height);
                map.put("type", Constants.DEVELOPPROJECT_LENGTH);

                List<Map<String, Object>> resultList = getGrowthResult(Constants.GROWTH_AGE_TYPE_CORRECT, map, patient);
                if (!CollectionUtils.isEmpty(resultList)) {
                    result.put("heightResult", resultList);
                }

                List<Map<String, Object>> actualList = getGrowthResult(Constants.GROWTH_AGE_TYPE_ACTUAL, map, patient);
                if (!CollectionUtils.isEmpty(actualList)) {
                    actualResult.put("heightResult", actualList);
                }
            }
            if (!StringUtils.isEmpty(headCircumference)) {
                map.put("values", headCircumference);
                map.put("type", Constants.DEVELOPPROJECT_HEAD);

                List<Map<String, Object>> resultList = getGrowthResult(Constants.GROWTH_AGE_TYPE_CORRECT, map, patient);
                if (!CollectionUtils.isEmpty(resultList)) {
                    result.put("headtResult", resultList);
                }

                List<Map<String, Object>> actualList = getGrowthResult(Constants.GROWTH_AGE_TYPE_ACTUAL, map, patient);
                if (!CollectionUtils.isEmpty(actualList)) {
                    actualResult.put("headtResult", actualList);
                }
            }
            paramMap.put("result", JSON.toJSONString(result));
            paramMap.put("actualResult", JSON.toJSONString(actualResult));
        } catch (Exception e) {
            logger.error("计算百分位异常 不影响数据录入", e);
        }

        familyReportDAO.saveGrowthRecord(paramMap);
        addGrowthGuide(patient, seq);
		/*}else{
			paramMap.put("id", growthMap.get("ID"));
			familyReportDAO.updateGrowthRecord(paramMap);
		}*/
        param = new HashMap<String, Object>();
        param.put("id", paramMap.get("id"));

        //入历史表
		/*paramMap.put("id",seq);
		familyReportDAO.saveGrowthRecordHis(paramMap);*/

        return param;
    }

    private List<Map<String, Object>> getGrowthResult(String ageType,
                                                      Map<String, Object> map, Patient patient) throws Exception {
        Map<String, Object> percentiles = getGrowthPercentiles(map, ageType, patient);
        Map<String, Object> zscore = getGrowthZscore(map, ageType, patient);

        Map<String, Object> rsMap = new HashMap<String, Object>();
        if (percentiles != null && !percentiles.isEmpty()) {
            rsMap.put("percentileRange", percentiles.get("percentiles"));
        }
        if (zscore != null && !zscore.isEmpty()) {
            rsMap.put("zcorerange", zscore.get("zscore"));
        }

        rsMap.put("time", percentiles.get("time"));
        rsMap.put("sumary", percentiles.get("sumary"));
        rsMap.put("level", percentiles.get("level"));

        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        if (!rsMap.isEmpty()) {
            list.add(rsMap);
        }
        return list;
    }

    @Override
    @Transactional
    public Map<String, Object> addGrowthRecord(Map<String, Object> paramMap)
            throws Exception {
        Map<String, Object> param = new HashMap<String, Object>();
        if (null == paramMap.get("testTime")) {
            paramMap.put("testTime", DateUtil.getDate_8(new Date()));
        } else {
            paramMap.put("testTime", paramMap.get("testTime"));
        }
        if (null == paramMap.get("sourceType")) {
            paramMap.put("sourceType", Constants.SOURCE_TYPE_FOLLOW); //问卷评估
        }

        String weight = (String) paramMap.get("weight");
        String height = (String) paramMap.get("height");
        String headCircumference = (String) paramMap.get("headCircumference");

        Map<String, List<Map<String, Object>>> result = new HashMap<String, List<Map<String, Object>>>();
        Map<String, List<Map<String, Object>>> actualResult = new HashMap<String, List<Map<String, Object>>>();

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("tenantId", paramMap.get("tenantId"));
        map.put("userId", paramMap.get("userId"));
        map.put("testTime", paramMap.get("testTime"));
        Patient patient = patientdao.selectById(map);
        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "生长发育评估记录患者信息不存在");
        }


        if (!StringUtils.isEmpty(weight)) {
            map.put("values", weight);
            map.put("type", Constants.DEVELOPPROJECT_WEIGHT);
            List<Map<String, Object>> resultList = getGrowthResult(Constants.GROWTH_AGE_TYPE_CORRECT, map, patient);
            if (!CollectionUtils.isEmpty(resultList)) {
                result.put("weightResult", resultList);
            }

            List<Map<String, Object>> actualList = getGrowthResult(Constants.GROWTH_AGE_TYPE_ACTUAL, map, patient);
            if (!CollectionUtils.isEmpty(actualList)) {
                actualResult.put("weightResult", actualList);
            }
        }
        if (!StringUtils.isEmpty(height)) {
            map.put("values", height);
            map.put("type", Constants.DEVELOPPROJECT_LENGTH);

            List<Map<String, Object>> resultList = getGrowthResult(Constants.GROWTH_AGE_TYPE_CORRECT, map, patient);
            if (!CollectionUtils.isEmpty(resultList)) {
                result.put("heightResult", resultList);
            }

            List<Map<String, Object>> actualList = getGrowthResult(Constants.GROWTH_AGE_TYPE_ACTUAL, map, patient);
            if (!CollectionUtils.isEmpty(actualList)) {
                actualResult.put("heightResult", actualList);
            }
        }
        if (!StringUtils.isEmpty(headCircumference)) {
            map.put("values", headCircumference);
            map.put("type", Constants.DEVELOPPROJECT_HEAD);

            List<Map<String, Object>> resultList = getGrowthResult(Constants.GROWTH_AGE_TYPE_CORRECT, map, patient);
            if (!CollectionUtils.isEmpty(resultList)) {
                result.put("headtResult", resultList);
            }

            List<Map<String, Object>> actualList = getGrowthResult(Constants.GROWTH_AGE_TYPE_ACTUAL, map, patient);
            if (!CollectionUtils.isEmpty(actualList)) {
                actualResult.put("headtResult", actualList);
            }
        }


        String seq = SeqUtil.getSeqNo();
        //20180410 如果没有传入createTime 取当前时间
        if (StringUtils.isEmpty(paramMap.get("createTime"))) {
            paramMap.put("createTime", DateUtil.getSysDateA());
        }
        paramMap.put("doctorId", paramMap.get("authorId"));
//		paramMap.put("testTime",param.get("testTime"));
        paramMap.put("id", seq);
        //增加月度评估 整体提交id
        paramMap.put("result", JSON.toJSONString(result));
        paramMap.put("actualResult", JSON.toJSONString(actualResult));
        familyReportDAO.saveGrowthRecord(paramMap);

        addGrowthGuide(patient, seq);

        param = new HashMap<String, Object>();
        param.put("id", paramMap.get("id"));
        return param;
    }

    private void addGrowthGuide(Patient patient, String seq) throws Exception {
        if (null == patient) {
            return;
        }
        Long birthLong = ToolUtils.getCorrect(patient.getBirthday(), patient.getPregnancyDay());//生日时间戳
        long ageGuid = (new Date().getTime() - birthLong) / (1000 * 60 * 60 * 24); //纠正年龄 指导方案时候使用
        Map<String, Object> guidMap = new HashMap<String, Object>();
        guidMap.put("questionModuleId", Constants.QUESTION_MODULE_ID_GROWTH);
        guidMap.put("age", ageGuid);
        List<Map<String, Object>> guideList = familyReportDAO.selectHealthGuideDetail(guidMap);
        if (!CollectionUtils.isEmpty(guideList)) {
            List<PtEvaluationGuide> list = new ArrayList<PtEvaluationGuide>();
            if (!CollectionUtils.isEmpty(guideList)) {
                Map<String, Object> temp = null;
                PtEvaluationGuide guide = null;
                for (int i = 0; i < guideList.size(); i++) {
                    temp = guideList.get(i);
                    guide = new PtEvaluationGuide();
                    guide.setEvaluationId(seq);
                    guide.setCreateAuthor("admin");
                    guide.setCreateTime(DateUtil.getSysDateA());
                    guide.setId(SeqUtil.getSeqNo());
                    guide.setRemark("系统生长发育指导");
                    guide.setGuide((String) temp.get("note"));
                    guide.setSort((int) temp.get("sort"));
                    list.add(guide);
                }
                followEvaluationDao.saveBatchPtEvaluationGuide(list);
            }
        }
    }

    /**
     *
     */
    @Override
    public Map<String, Object> getGrowthPercentiles(Map<String, Object> paramMap, String ageType, Patient patient)
            throws Exception {
        float monthDay = 30.4F;
        int yearDay = 365;

        if (StringUtils.isEmpty(ageType)) {
            ageType = Constants.GROWTH_AGE_TYPE_CORRECT;
        }

        Map<String, Object> rspMap = new HashMap<String, Object>();
//		String flag = (String)paramMap.get("flag");
        String type = (String) paramMap.get("type");
        Map<String, Object> userPara = new HashMap<String, Object>();
        userPara.put("userId", paramMap.get("userId"));
        userPara.put("tenantId", paramMap.get("tenantId"));
//		map.put("status","1"));
        if (null == patient) {
            patient = patientdao.selectById(userPara);
        }

        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "生长发育评估记录患者信息不存在");
        }

        String testTime = (String) paramMap.get("testTime");
        final String birthday = patient.getBirthday();
        final Integer pregnancyDay = patient.getPregnancyDay();
//        Long birthLong = ToolUtils.getCorrect(birthday, pregnancyDay);//生日时间戳
        Map<String, Object> ageMap = new HashMap<>();
        ageMap.put("birthday", birthday);
        ageMap.put("pregnancyDay", pregnancyDay);
        ageMap.put("checkDate", paramMap.get("testTime"));

        long date = 0;
        if (StringUtils.isEmpty(testTime)) {
            date = new Date().getTime();
            testTime = DateUtil.getDate_8(new Date());
        } else {
            date = DateUtil.getDate_8(testTime).getTime();
        }
        HashMap map = new HashMap();
        map.put("birthday", birthday);
        map.put("pregnancyDay", pregnancyDay);
        map.put("checkDate", testTime);
        Long birthLong = ToolUtils.getCorrectCheckAge(map);//纠正年龄时间戳
        long ageDay = 0;
        //Edit by jiangq on 2022年07月04日 测评日期 >= 纠正年龄+10周(70天) || 孕周大于37周或者年龄大于2岁（上一步已经算过其实就是纠正年龄等于出生日期的实际年龄）
        if(Constants.GROWTH_AGE_TYPE_ACTUAL.equals(ageType) || date - (birthLong + 70 * 86400000L) >= 0 || birthLong == DateUtil.getDate_8(birthday).getTime()){
            if (Constants.GROWTH_AGE_TYPE_ACTUAL.equals(ageType)) {//按实际年龄计算  重新计算年龄
                birthLong = DateUtil.getDate_8(birthday).getTime();
            }
            ageDay = (date - birthLong) / (1000 * 60 * 60 * 24);
            //查询who标准数据
            Map<String, Object> whoMap = new HashMap<String, Object>();

            whoMap.put("gender", patient.getGender());
            long ageMonth = ageDay / yearDay;
            if (ageMonth <= 5) {
                whoMap.put("age", ageDay);
                whoMap.put("standardId", Constants.WHO_STANDARD_ID);
                rspMap.put("time", "2013");
            } else {//大于5岁
                whoMap.put("ageMonth", (long) (ageDay / monthDay));
                whoMap.put("standardId", Constants.WHO_STANDARD_ID_FIVEYEAR);
                rspMap.put("time", "2007");
            }
            List<Map<String, Object>> whoMaplist = null;
            Map standardParam = new HashMap<String, Object>();
            whoMap.put("standardType", Constants.WHO_STANDARD_TYPE_PERCENT);
            if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_HEAD);
            } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_WEIGHT);
            } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_LENGTH);
            } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_AGEFORWH);
            } else if (Constants.DEVELOPPROJECT_LENGTHFORWEIGHT.equals(type)) {
                //当小于两岁时 需要查询身高别体重
                standardParam.put("developProjectId", Constants.DEVELOPPROJECT_LENGTHFORWEIGHT);
                standardParam.put("gender", patient.getGender());
                standardParam.put("standardId", Constants.WHO_STANDARD_ID);
                standardParam.put("standardType", Constants.WHO_STANDARD_TYPE_PERCENT);
            } else {
                throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "type值不符合要求");
            }
            whoMap.put("length", 0);
            //返回超过年龄 无标准数据

            String percent = "";
            String sumary = "";
            String level = "";
            if (Constants.DEVELOPPROJECT_LENGTHFORWEIGHT.equals(type)) {
                whoMaplist = familyReportDAO.selectStandardwfhList(standardParam);
                whoMaplist = whoMaplist.stream().filter(item -> Double.parseDouble(item.get("length").toString()) == Double.parseDouble((paramMap.get("height").toString()))).collect(Collectors.toList());
            }else{
                whoMaplist = familyReportDAO.selectDevelopStandardForWho(whoMap);
            }
            if (!CollectionUtils.isEmpty(whoMaplist)) {//
                double p1 = (double) whoMaplist.get(0).get("SD4NEG");
                double p3 = (double) whoMaplist.get(0).get("SD3NEG");
                double p10 = (double) whoMaplist.get(0).get("SD2NEG");
                double p25 = (double) whoMaplist.get(0).get("SD1NEG");
                double p50 = (double) whoMaplist.get(0).get("SD0");
                double p75 = (double) whoMaplist.get(0).get("SD1");
                double p90 = (double) whoMaplist.get(0).get("SD2");
                double p97 = (double) whoMaplist.get(0).get("SD3");
                double p99 = (double) whoMaplist.get(0).get("SD4");

                double p15 = (double) whoMaplist.get(0).get("P15");
                double p85 = (double) whoMaplist.get(0).get("P85");
                double p01 = (double) whoMaplist.get(0).get("P01");
                double p5 = (double) whoMaplist.get(0).get("P5");
                double p95 = (double) whoMaplist.get(0).get("P95");
                double p999 = (double) whoMaplist.get(0).get("P999");

                double value = Double.parseDouble(String.valueOf(paramMap.get("values")));

                // 50为分隔   50以上  > && <=    50以下 >= && <
                if (value < p01) {
                    percent = "<0.1%";
                } else if (value >= p01 && value < p1) {
                    percent = "0.1%~1%";
                    double a = (p1 - p01) / 0.9;
                    double b = value - p01;
                    double c = b / a;
                    percent = Math.round(0.1 + c) + "%";
                } else if (value >= p1 && value < p3) {
                    percent = "1%~3%";
                    double a = (p3 - p1) / 2;
                    double b = value - p1;
                    double c = b / a;
                    percent = Math.round(1 + c) + "%";
                } else if (value >= p3 && value < p5) {
                    percent = "3%~5%";
                    double a = (p3 - p1) / 2;
                    double b = value - p1;
                    double c = b / a;
                    percent = Math.round(3 + c) + "%";
                } else if (value >= p5 && value < p10) {
                    percent = "5%~10%";
                    double a = (p10 - p5) / 5;
                    double b = value - p5;
                    double c = b / a;
                    percent = Math.round(5 + c) + "%";
                } else if (value >= p10 && value < p15) {
                    percent = "10%~15%";
                    double a = (p15 - p10) / 5;
                    double b = value - p10;
                    double c = b / a;
                    percent = Math.round(10 + c) + "%";
                } else if (value >= p15 && value < p25) {
                    percent = "15%~25%";
                    double a = (p25 - p15) / 10;
                    double b = value - p15;
                    double c = b / a;
                    percent = Math.round(15 + c) + "%";
                } else if (value >= p25 && value < p50) {
                    percent = "25%~50%";
                    double a = (p50 - p25) / 25;
                    double b = value - p25;
                    double c = b / a;
                    percent = Math.round(25 + c) + "%";
                } else if (value >= p50 && value <= p75) {
                    percent = "50%~75%";
                    double a = (p75 - p50) / 25;
                    double b = value - p50;
                    double c = b / a;
                    percent = Math.round(50 + c) + "%";
                } else if (value > p75 && value <= p85) {
                    percent = "75%~85%";
                    double a = (p85 - p75) / 10;
                    double b = value - p75;
                    double c = b / a;
                    percent = Math.round(75 + c) + "%";
                } else if (value > p85 && value <= p90) {
                    percent = "85%~90%";
                    double a = (p90 - p85) / 5;
                    double b = value - p85;
                    double c = b / a;
                    percent = Math.round(85 + c) + "%";
                } else if (value > p90 && value <= p95) {
                    percent = "90%~95%";
                    double a = (p95 - p90) / 5;
                    double b = value - p90;
                    double c = b / a;
                    percent = Math.round(90 + c) + "%";
                } else if (value > p95 && value <= p97) {
                    percent = "95%~97%";
                    double a = (p97 - p95) / 2;
                    double b = value - p95;
                    double c = b / a;
                    percent = Math.round(95 + c) + "%";
                } else if (value > p97 && value <= p99) {
                    percent = "97%~99%";
                    double a = (p99 - p97) / 5;
                    double b = value - p97;
                    double c = b / a;
                    percent = Math.round(97 + c) + "%";
                } else if (value > p99 && value <= p999) {
                    percent = "99%~99.9%";
                    double a = (p999 - p99) / 0.9;
                    double b = value - p99;
                    double c = b / a;
                    percent = Math.round(99 + c) + "%";
                } else if (value > p999) {
                    percent = ">99.9%";
                    percent = 99 + Math.round(((value - p999)/100)) + "%";
                }

                //结论
                if (value < p3) {
                    level = Constants.LEVELH;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headH;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightH;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightH;
                    } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(type)) {
                        sumary = Constants.bmiH;
                    }
                } else if (value >= p3 && value < p10) {
                    level = Constants.LEVELG;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headG;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightG;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightG;
                    } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(type)) {
                        sumary = Constants.bmiG;
                    }
                } else if (value >= p10 && value < p25) {
                    level = Constants.LEVELF;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headF;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightF;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightF;
                    } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(type)) {
                        sumary = Constants.bmiF;
                    }
                } else if (value >= p25 && value < p50) {
                    level = Constants.LEVELE;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headE;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightE;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightE;
                    } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(type)) {
                        sumary = Constants.bmiE;
                    }
                } else if (value >= p50 && value <= p75) {
                    level = Constants.LEVELD;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headD;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightD;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightD;
                    } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(type)) {
                        sumary = Constants.bmiD;
                    }
                } else if (value > p75 && value <= p90) {
                    level = Constants.LEVELC;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headC;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightC;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightC;
                    } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(type)) {
                        sumary = Constants.bmiC;
                    }
                } else if (value > p90 && value <= p97) {
                    level = Constants.LEVELB;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headB;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightB;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightB;
                    } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(type)) {
                        sumary = Constants.bmiB;
                    }
                } else if (value >= p97) {
                    level = Constants.LEVELA;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headA;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightA;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightA;
                    } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(type)) {
                        sumary = Constants.bmiA;
                    }
                }
            } else {
//				rspMap.put("percentiles","");
                throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_GROWTHS_STANDARD_WHO_AGE_OVER_MAXAGE, "该用户不在评测年龄范围内！");
            }
            rspMap.put("percentiles", percent);
            rspMap.put("sumary", sumary);
            rspMap.put("level", level);
        } else { //fendon曲线
            rspMap = getGrowthFentonPercent(paramMap, patient);
        }

        return rspMap;
    }

    //查询
    @Override
    public Map<String, Object> getGrowthZscore(Map<String, Object> paramMap, String ageType, Patient patient)
            throws Exception {
        float monthDay = 30.4F;
        int yearDay = 365;

        if (StringUtils.isEmpty(ageType)) {
            ageType = Constants.GROWTH_AGE_TYPE_CORRECT;
        }
        Map<String, Object> rspMap = new HashMap<String, Object>();
//		String flag = (String)paramMap.get("flag");
        String type = (String) paramMap.get("type");
        Map<String, Object> userPara = new HashMap<String, Object>();
        userPara.put("userId", paramMap.get("userId"));
        userPara.put("tenantId", paramMap.get("tenantId"));
//		map.put("status","1"));
        if (null == patient) {
            patient = patientdao.selectById(userPara);
        }

        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "生长发育评估记录患者信息不存在");
        }

        String birthday = patient.getBirthday();
        Integer pregnancyDay = patient.getPregnancyDay();

        String testTime = (String) paramMap.get("testTime");
        long date = 0;
        if (StringUtils.isEmpty(testTime)) {
            date = new Date().getTime();
            testTime = DateUtil.getDate_8(new Date());
        } else {
            date = DateUtil.getDate_8(testTime).getTime();
        }
        HashMap map = new HashMap();
        map.put("birthday", birthday);
        map.put("pregnancyDay", pregnancyDay);
        map.put("checkDate", testTime);
        Long birthLong =ToolUtils.getCorrectCheckAge(map);//生日时间戳
        long ageDay = 0;
        if(pregnancyDay < 259 && date - (birthLong + 70 * 86400000L) <= 0){
            rspMap = getGrowthFentonScore(paramMap, patient);
        }else{
            if(Constants.GROWTH_AGE_TYPE_ACTUAL.equals(ageType)){
                birthLong = DateUtil.getDate_8(birthday).getTime();
                ageDay = (date - birthLong) / (1000 * 60 * 60 * 24);
            }
            //查询who标准数据
            Map<String, Object> whoMap = new HashMap<String, Object>();

            long ageMonth = ageDay / yearDay;
            if (ageMonth <= 5) {
                whoMap.put("age", ageDay);
                whoMap.put("standardId", Constants.WHO_STANDARD_ID);
                rspMap.put("time", "2013");
            } else {//大于5岁
                whoMap.put("ageMonth", (long) (ageDay / monthDay));
                whoMap.put("standardId", Constants.WHO_STANDARD_ID_FIVEYEAR);
                rspMap.put("time", "2007");
            }

            whoMap.put("gender", patient.getGender());
            whoMap.put("standardType", Constants.WHO_STANDARD_TYPE_SCORE);
            if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_HEAD);
            } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_WEIGHT);
            } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_LENGTH);
            } else if (Constants.DEVELOPPROJECT_AGEFORWH.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_AGEFORWH);
            } else {
                throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "type值不符合要求");
            }
            whoMap.put("length", 0);
            //返回超过年龄 无标准数据

            String zscore = "";
            String sumary = "";
            String level = "";
            List<Map<String, Object>> whoMaplist = familyReportDAO.selectDevelopStandardForWho(whoMap);
            if (!CollectionUtils.isEmpty(whoMaplist)) {//
                double sd4neg = (double) whoMaplist.get(0).get("SD4NEG");
                double sd3neg = (double) whoMaplist.get(0).get("SD3NEG");
                double sd2neg = (double) whoMaplist.get(0).get("SD2NEG");
                double sd1neg = (double) whoMaplist.get(0).get("SD1NEG");
                double sd0 = (double) whoMaplist.get(0).get("SD0");
                double sd1 = (double) whoMaplist.get(0).get("SD1");
                double sd2 = (double) whoMaplist.get(0).get("SD2");
                double sd3 = (double) whoMaplist.get(0).get("SD3");
                double sd4 = (double) whoMaplist.get(0).get("SD4");

                double value = Double.parseDouble(String.valueOf(paramMap.get("values")));

                // 50为分隔   50以上  > && <=    50以下 >= && <
					/*if(value < sd4neg ){
						zscore = "<-4";
					}else if(value >= sd4neg && value < sd3neg ){
						zscore = "-4~-3";
					}else if(value >= sd3neg && value < sd2neg){
						zscore = "-3~-2";
					}else if(value >= sd2neg && value < sd1neg){
						zscore = "-2~-1";
					}else if(value>=sd1neg && value < sd0){
						zscore = "-1~0";
					}else if(value>=sd0 && value <= sd1){
						zscore = "0~1";
					}else if(value>=sd1 && value <=sd2){
						zscore = "1~2";
					}else if(value>sd2 && value <=sd3){
						zscore = "2~3";
					}else if(value>sd3 && value <=sd4){
						zscore = "3~4";
					}else if(value>sd4){
						zscore = ">4";
					}*/
                if (value < sd4neg) {
                    zscore = "<-4";
                    level = Constants.LEVELH;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headH;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightH;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightH;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.bmiH;
                    }
                } else if (value >= sd4neg && value < sd3neg) {
                    level = Constants.LEVELH;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headH;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightH;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightH;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.bmiH;
                    }
                    zscore = "-4~-3";
                } else if (value >= sd3neg && value < sd2neg) {
                    level = Constants.LEVELG;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headG;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightG;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightG;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.bmiG;
                    }
                    zscore = "-3~-2";
                } else if (value >= sd2neg && value < sd1neg) {
                    level = Constants.LEVELF;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headF;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightF;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightF;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.bmiF;
                    }
                    zscore = "-2~-1";
                } else if (value >= sd1neg && value < sd0) {
                    level = Constants.LEVELE;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headE;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightE;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightE;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.bmiE;
                    }
                    zscore = "-1~0";
                } else if (value >= sd0 && value <= sd1) {
                    level = Constants.LEVELD;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headD;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightD;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightD;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.bmiD;
                    }
                    zscore = "0~1";
                } else if (value >= sd1 && value <= sd2) {
                    level = Constants.LEVELC;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headC;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightC;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightC;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.bmiC;
                    }
                    zscore = "1~2";
                } else if (value > sd2 && value <= sd3) {
                    level = Constants.LEVELB;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headB;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightB;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightB;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.bmiB;
                    }
                    zscore = "2~3";
                } else if (value > sd3 && value <= sd4) {
                    level = Constants.LEVELA;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headA;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightA;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightA;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.bmiA;
                    }
                    zscore = "3~4";
                } else if (value > sd4) {
                    level = Constants.LEVELA;
                    if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                        sumary = Constants.headA;
                    } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        sumary = Constants.weightA;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.heightA;
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        sumary = Constants.bmiA;
                    }
                    zscore = ">4";
                }
            } else {
//				rspMap.put("percentiles","");
                throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_GROWTHS_STANDARD_WHO_AGE_OVER_MAXAGE, "该用户不在评测年龄范围内！");
            }
            rspMap.put("zscore", zscore);
            rspMap.put("level", level);
            rspMap.put("sumary", sumary);
        }
        return rspMap;
    }

    @Override
    public Map<String, Object> getlastGrowth(Map<String, Object> paramMap)
            throws Exception {
        List<Map<String, Object>> list = familyReportDAO.selectGrowthList(paramMap);
        if (!CollectionUtils.isEmpty(list)) {
            Map<String, Object> map = list.get(0);
            map.put("createTime", DateUtil.getTimeStampSec(map.get("createTime").toString()));
            return map;
        }
        return null;
    }

    private List<Map<String, Object>> getGrowthFentonCurvedata(Map<String, Object> paramMap,
                                                               Patient patient, List<Map<String, Object>> growthDetailsList, Object testTime) throws Exception {
        //查询曲线类型 条件输入
        String flagType = (String) paramMap.get("flag");
        String type = (String) paramMap.get("type");
        String scoreType = (String) paramMap.get("scoreType");
//		String ageType = (String)paramMap.get("ageType");

        String valueFlag = (String) paramMap.get("valueFlag");

        Map<String, Object> weightMap = new HashMap<String, Object>();
        Map<String, Object> lengthMap = new HashMap<String, Object>();
        Map<String, Object> headMap = new HashMap<String, Object>();

        Object testTimeHis = null;
        //计算当前节点X轴
        long endTime = 0;
        long endTimeHis = 0;
        Date testDate;
        if (StringUtils.isEmpty(testTime)) {
            testTime = DateUtil.getDate_8(new Date());
            testDate = (Date) testTime;
        } else {
            Date testTime1 = DateUtil.getDate(testTime.toString());
            testDate = testTime1;
        }

        //调用fenton曲线  早产儿 并且 监测时胎龄<50周  其他走正常曲线
        Long birthLong = DateUtil.getDate_8(patient.getBirthday()).getTime();//生日时间戳

        String ageType = (String) paramMap.get("ageType");
        if (StringUtils.isEmpty(ageType)) {
            ageType = Constants.GROWTH_AGE_TYPE_CORRECT;
        }

        int pregnancyDay = patient.getPregnancyDay();
        if (Constants.GROWTH_AGE_TYPE_ACTUAL.equals(ageType)) {
            pregnancyDay = 280;
        }
        endTime = (testDate.getTime() - birthLong) / (1000 * 60 * 60 * 24);
        endTime = pregnancyDay + endTime;

        int xMin = 22;
        int xMax = 50;
        String timeUnit = "周";
        String redisKey = Constants.FENTON_STANDARD_TYPE_PERCENT;
        if (Constants.GROWTH_SCORE_ZSCORE.equals(scoreType)) {
            redisKey = Constants.FENTON_STANDARD_TYPE_SCORE;
        }
        //每个月 平均天数
        float weekDay = 7F;

        weightMap.put("xMax", xMax);
        weightMap.put("xMin", xMin);
        weightMap.put("timeUnit", timeUnit);

        lengthMap.put("xMax", xMax);
        lengthMap.put("xMin", xMin);
        lengthMap.put("timeUnit", timeUnit);

        headMap.put("xMax", xMax);
        headMap.put("xMin", xMin);
        headMap.put("timeUnit", timeUnit);

//	    cal.setTime(birthdayDate);
        List<Map<String, Object>> hights = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> weights = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> heads = new ArrayList<Map<String, Object>>();

        Map<String, Object> map = null;
        Map<String, Object> growthDetailsMap = null;

        float xdate = (float) endTime / weekDay;

        if (!StringUtils.isEmpty(type)) {

            if (!StringUtils.isEmpty(valueFlag)) {
                Object weight = paramMap.get("weight");
                if (!StringUtils.isEmpty(weight)) {
                    map = new HashMap<String, Object>();
                    map.put("xDate", xdate);
                    map.put("yDate", weight);
                    map.put("flag", 1);

                    paramMap.put("values", weight);
                    paramMap.put("type", Constants.DEVELOPPROJECT_WEIGHT);
                    Map<String, Object> percentiles = getGrowthFentonPercent(paramMap, patient);
                    Map<String, Object> zscore = getGrowthFentonScore(paramMap, patient);

                    Map<String, Object> rsMap = new HashMap<String, Object>();
                    if (percentiles != null && !percentiles.isEmpty()) {
                        rsMap.put("percentileRange", percentiles.get("percentiles"));
                        rsMap.put("time", percentiles.get("time"));
                        rsMap.put("sumary", percentiles.get("sumary"));
                    }
                    if (zscore != null && !zscore.isEmpty()) {
                        rsMap.put("zcorerange", zscore.get("zscore"));
                        rsMap.put("time", zscore.get("time"));
                        rsMap.put("sumary", percentiles.get("sumary"));
                    }

                    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
                    if (!rsMap.isEmpty()) {
                        list.add(rsMap);
                    }
                    map.put("result", list);
                    weights.add(map);
                }

                Object height = paramMap.get("hight");
                if (!StringUtils.isEmpty(height)) {
                    map = new HashMap<String, Object>();
                    map.put("xDate", xdate);
                    map.put("yDate", height);
                    map.put("flag", 1);

                    paramMap.put("values", height);
                    paramMap.put("type", Constants.DEVELOPPROJECT_LENGTH);
                    Map<String, Object> percentiles = getGrowthFentonPercent(paramMap, patient);
                    Map<String, Object> zscore = getGrowthFentonScore(paramMap, patient);

                    Map<String, Object> rsMap = new HashMap<String, Object>();
                    if (percentiles != null && !percentiles.isEmpty()) {
                        rsMap.put("percentileRange", percentiles.get("percentiles"));
                        rsMap.put("time", percentiles.get("time"));
                        rsMap.put("sumary", percentiles.get("sumary"));
                    }
                    if (zscore != null && !zscore.isEmpty()) {
                        rsMap.put("zcorerange", zscore.get("zscore"));
                        rsMap.put("time", zscore.get("time"));
                        rsMap.put("sumary", percentiles.get("sumary"));
                    }

                    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
                    if (!rsMap.isEmpty()) {
                        list.add(rsMap);
                    }
                    map.put("result", list);
                    hights.add(map);
                }

                Object head = paramMap.get("headCircumference");
                if (!StringUtils.isEmpty(head)) {
                    map = new HashMap<String, Object>();
                    map.put("xDate", xdate);
                    map.put("yDate", head);
                    map.put("flag", 1);

                    paramMap.put("values", head);
                    paramMap.put("type", Constants.DEVELOPPROJECT_HEAD);
                    Map<String, Object> percentiles = getGrowthFentonPercent(paramMap, patient);
                    Map<String, Object> zscore = getGrowthFentonScore(paramMap, patient);

                    Map<String, Object> rsMap = new HashMap<String, Object>();
                    if (percentiles != null && !percentiles.isEmpty()) {
                        rsMap.put("percentileRange", percentiles.get("percentiles"));
                        rsMap.put("time", percentiles.get("time"));
                        rsMap.put("sumary", percentiles.get("sumary"));
                    }
                    if (zscore != null && !zscore.isEmpty()) {
                        rsMap.put("zcorerange", zscore.get("zscore"));
                        rsMap.put("time", zscore.get("time"));
                        rsMap.put("sumary", percentiles.get("sumary"));
                    }

                    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
                    if (!rsMap.isEmpty()) {
                        list.add(rsMap);
                    }
                    map.put("result", list);
                    heads.add(map);
                }
                paramMap.remove("values");
                paramMap.remove("type");
            } else {
                map = new HashMap<String, Object>();
                map.put("xDate", xdate);
                map.put("yDate", paramMap.get("values"));
                map.put("flag", "1");
                try {
                    Map<String, Object> percentiles = getGrowthFentonPercent(paramMap, patient);
                    Map<String, Object> zscore = getGrowthFentonScore(paramMap, patient);

                    Map<String, Object> rsMap = new HashMap<String, Object>();
                    if (percentiles != null && !percentiles.isEmpty()) {
                        rsMap.put("percentileRange", percentiles.get("percentiles"));
                        rsMap.put("time", percentiles.get("time"));
                    }
                    if (zscore != null && !zscore.isEmpty()) {
                        rsMap.put("zcorerange", zscore.get("zscore"));
                        rsMap.put("time", zscore.get("time"));
                    }

                    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
                    if (!rsMap.isEmpty()) {
                        list.add(rsMap);
                    }
                    map.put("result", list);
                } catch (Exception e) {
                    logger.error("计算百分位有误", e);
                }

                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    heads.add(map);
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    weights.add(map);
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    hights.add(map);
                } else {
                    throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "type值不符合定义类型");
                }
            }
        }

        if (!CollectionUtils.isEmpty(growthDetailsList)) {
            for (int j = 0; j < growthDetailsList.size(); j++) {
                growthDetailsMap = growthDetailsList.get(j);
                map = new HashMap<String, Object>();
                int flag = 0;//是否当前记录
                if (StringUtils.isEmpty(type)) {
                    if (growthDetailsMap.get("growthRecordId").equals(paramMap.get("growthRecordId"))) {
                        //当前记录
                        flag = 1;
                        xdate = endTime / weekDay;
                    } else {
                        if (testTime.equals(growthDetailsMap.get("testTime"))) {
                            continue;
                        }

                        //计算每次记录的 X轴
                        testTimeHis = growthDetailsMap.get("testTime");
                        endTimeHis = (DateUtil.getDate_8(testTimeHis.toString()).getTime() - birthLong) / (1000 * 60 * 60 * 24);
                        endTimeHis = pregnancyDay + endTimeHis;
                        xdate = endTimeHis / weekDay;
                    }
                } else {// 上传记录日期和查询出有重复的 日期的 去掉查出来的记录
                    if (testTime.equals(growthDetailsMap.get("testTime").toString())) {
                        continue;
                    }
                    testTimeHis = growthDetailsMap.get("testTime");
                    endTimeHis = (DateUtil.getDate_8(testTimeHis.toString()).getTime() - birthLong) / (1000 * 60 * 60 * 24);
                    endTimeHis = pregnancyDay + endTimeHis;
                    xdate = endTimeHis / weekDay;
                }

                map.put("xDate", xdate);
                map.put("flag", flag);
                map.put("yDate", growthDetailsMap.get("weight"));

                String result = "";
                if (null != growthDetailsMap.get("result")) {
                    try {
                        result = JSON.parseObject(growthDetailsMap.get("result").toString()).getString("weightResult");
                        map.put("result", result);
                    } catch (Exception e) {
                        logger.error("fenton曲线结果 获取记录结果error", e);
                    }
                }

                weights.add(map);

                map = new HashMap<String, Object>();
                map.put("xDate", xdate);
                map.put("yDate", growthDetailsMap.get("hight"));
                map.put("flag", flag);

                if (null != growthDetailsMap.get("result")) {
                    try {
                        result = JSON.parseObject(growthDetailsMap.get("result").toString()).getString("heightResult");
                        map.put("result", result);
                    } catch (Exception e) {
                        logger.error("fenton曲线结果 获取记录结果error", e);
                    }
                }
                hights.add(map);

                map = new HashMap<String, Object>();
                map.put("xDate", xdate);
                map.put("yDate", growthDetailsMap.get("headCircumference"));
                map.put("flag", flag);

                if (null != growthDetailsMap.get("result")) {
                    try {
                        result = JSON.parseObject(growthDetailsMap.get("result").toString()).getString("headtResult");
                        map.put("result", result);
                    } catch (Exception e) {
                        logger.error("fenton曲线结果  获取记录结果error", e);
                    }
                }
                heads.add(map);
            }
        }

        weightMap.put("growthrecord", weights);
        lengthMap.put("growthrecord", hights);
        headMap.put("growthrecord", heads);
        //先从缓存查询  没有再查询数据库
        Jedis jedis = null;

        Map<String, Object> weightMapSD = null;
        Map<String, Object> lengthMapSD = null;
        Map<String, Object> headMapSD = null;

        try {
            jedis = jedisPool.getResource();
            jedis.select(Constants.REDIS_DB_INDEX_EVALUATION);
            String str = "";

            if (patient.getGender().equals(Constants.GENDER_FOR_FEMALE)) {
                redisKey += ":GIRLS";
            } else {
                redisKey += ":BOYS";
            }
            str = jedis.get(Constants.FENTON_KEY_WEIGHT + redisKey);
            if (!StringUtils.isEmpty(str)) {
                weightMapSD = JSONObject.parseObject(str);
            }
            str = jedis.get(Constants.FENTON_KEY_LENGTH + redisKey);
            if (!StringUtils.isEmpty(str)) {
                lengthMapSD = JSONObject.parseObject(str);
            }

            str = jedis.get(Constants.FENTON_KEY_HEAD + redisKey);
            if (!StringUtils.isEmpty(str)) {
                headMapSD = JSONObject.parseObject(str);
            }

            if (headMapSD == null || lengthMapSD == null || weightMapSD == null) {
                //有一个为空 则从数据库查询
                weightMapSD = new HashMap<String, Object>();
                lengthMapSD = new HashMap<String, Object>();
                headMapSD = new HashMap<String, Object>();

                List<Map<String, Object>> standardList = new ArrayList<Map<String, Object>>();
                Map<String, Object> standardParam = new HashMap<String, Object>();

                standardParam.put("age", xMax * weekDay); //50周

                standardParam.put("gender", patient.getGender());
                standardParam.put("standardId", Constants.WHO_STANDARD_ID);//标准曲线版本
                standardParam.put("standardType", Constants.FENTON_STANDARD_TYPE_PERCENT);
                if (Constants.GROWTH_SCORE_ZSCORE.equals(scoreType)) {//如果计算zscore 则传zscore类型
                    standardParam.put("standardType", Constants.FENTON_STANDARD_TYPE_SCORE);
                }
                standardList = familyReportDAO.selectStandardList(standardParam);
                if (CollectionUtils.isEmpty(standardList)) {
                    throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_GROWTHS_STANDARD_FENTON_NOT_EXIST, "fenton曲线数据不存在");
                }

                //FENTON数据曲线处理
                processFentonData(flagType, scoreType, weightMapSD, lengthMapSD,
                        headMapSD, standardList);

                jedis.set(Constants.FENTON_KEY_WEIGHT + redisKey, JSONObject.toJSONString(weightMapSD));
                jedis.set(Constants.FENTON_KEY_LENGTH + redisKey, JSONObject.toJSONString(lengthMapSD));
                jedis.set(Constants.FENTON_KEY_HEAD + redisKey, JSONObject.toJSONString(headMapSD));
            }

        } catch (Exception jex) {
            logger.error("redis连接异常..." + jex.getMessage());
            throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_REDIS_CONNECT_ERROR, "Redis缓存连接失败!"));
        } finally {
            if (null != jedis) {
                try {
                    jedis.close();
                    logger.warn("close redis connection...");
                } catch (Exception ex) {
                    ex.printStackTrace();
                    throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_REDIS_CONNECT_CLOSE_FAILED,
                            "Redis缓存关闭失败!"));
                }
            }
        }

        weightMap.putAll(weightMapSD);
        lengthMap.putAll(lengthMapSD);
        headMap.putAll(headMapSD);

        ArrayList<Map<String, Object>> rsp = new ArrayList<Map<String, Object>>();
        Map<String, Object> rspMap = new HashMap<String, Object>();

        rspMap = new HashMap<String, Object>();
        rspMap.put("curvedata", weightMap);
        rspMap.put("type", Constants.DEVELOPPROJECT_WEIGHT);
        rspMap.put("standardName", Constants.FENTON_STANDARD_NAME);
        rsp.add(rspMap);

        rspMap = new HashMap<String, Object>();
        rspMap.put("curvedata", lengthMap);
        rspMap.put("type", Constants.DEVELOPPROJECT_LENGTH);
        rspMap.put("standardName", Constants.FENTON_STANDARD_NAME);
        rsp.add(rspMap);

        rspMap = new HashMap<String, Object>();
        rspMap.put("curvedata", headMap);
        rspMap.put("type", Constants.DEVELOPPROJECT_HEAD);
        rspMap.put("standardName", Constants.FENTON_STANDARD_NAME);
        rsp.add(rspMap);

        return rsp;
    }

    //5岁以上 生长发育数据
    private List<Map<String, Object>> getGrowthFiveOverCurvedata(Map<String, Object> paramMap,
                                                                 Patient patient, List<Map<String, Object>> growthDetailsList, Object testTime) throws Exception {
        //查询曲线类型 条件输入  //固定2007数据
        String flagType = (String) paramMap.get("flag");
        String type = (String) paramMap.get("type");
        String scoreType = (String) paramMap.get("scoreType");
        String ageType = (String) paramMap.get("ageType");

        String valueFlag = (String) paramMap.get("valueFlag");

        Map<String, Object> weightMap = new HashMap<String, Object>();
        Map<String, Object> lengthMap = new HashMap<String, Object>();
        Map<String, Object> bmiMap = new HashMap<String, Object>();

        Object testTimeHis = null;
        //计算当前节点X轴
        long endTime = 0;
        long endTimeHis = 0;
        Date testdate = DateUtil.getDate_8(testTime.toString());

        //5岁以上 身高(5-19) 体重(5-10) bmi(5-19)数据
        Long birthLong = DateUtil.getDate_8(patient.getBirthday()).getTime();//生日时间戳
        endTime = (testdate.getTime() - birthLong) / (1000 * 60 * 60 * 24);

        int xMin = 0;
        int xMax = 0;
        String timeUnit = "年";

        String redisKey = Constants.WHO_STANDARD_TYPE_PERCENT;
        if (Constants.GROWTH_SCORE_ZSCORE.equals(scoreType)) {
            redisKey = Constants.WHO_STANDARD_TYPE_SCORE;
        }

        //每个月 平均天数
//		float monthDay = 30.4F;
        float yearDay = 365F;
        float xdate = 0;
//		Object testTimeHis=null;

        xMax = 19; //5-19月
        xMin = 5;
        timeUnit = "年";
        redisKey += "_FIVE_YEAR";

        weightMap.put("xMax", 10);
        weightMap.put("xMin", xMin);
        weightMap.put("timeUnit", timeUnit);

        lengthMap.put("xMax", xMax);
        lengthMap.put("xMin", xMin);
        lengthMap.put("timeUnit", timeUnit);

        bmiMap.put("xMax", xMax);
        bmiMap.put("xMin", xMin);
        bmiMap.put("timeUnit", timeUnit);

//	    cal.setTime(birthdayDate);
        List<Map<String, Object>> hights = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> weights = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> bmis = new ArrayList<Map<String, Object>>();

        Map<String, Object> map = null;
        Map<String, Object> growthDetailsMap = null;

        xdate = (float) endTime / yearDay;

        if (!StringUtils.isEmpty(type)) {
            if (!StringUtils.isEmpty(valueFlag)) {
                Object weight = paramMap.get("weight");
                if (!StringUtils.isEmpty(weight)) {
                    map = new HashMap<String, Object>();
                    map.put("xDate", xdate);
                    map.put("yDate", weight);
                    map.put("flag", 1);
                    try {
                        paramMap.put("values", weight);
                        paramMap.put("type", Constants.DEVELOPPROJECT_WEIGHT);
                        List<Map<String, Object>> list = getGrowthResult(ageType, paramMap, patient);
                        map.put("result", JSON.toJSONString(list));
                    } catch (Exception e) {
                        logger.error("计算百分位有误", e);
                    }
                    weights.add(map);
                }

                Object height = paramMap.get("hight");
                if (!StringUtils.isEmpty(height)) {
                    map = new HashMap<String, Object>();
                    map.put("xDate", xdate);
                    map.put("yDate", height);
                    map.put("flag", 1);
                    try {
                        paramMap.put("values", height);
                        paramMap.put("type", Constants.DEVELOPPROJECT_LENGTH);
                        List<Map<String, Object>> list = getGrowthResult(ageType, paramMap, patient);
                        map.put("result", JSON.toJSONString(list));
                    } catch (Exception e) {
                        logger.error("计算百分位有误", e);
                    }
                    hights.add(map);
                }

                map = new HashMap<String, Object>();
                if (null != weight && null != height) {
                    float weightF = Float.parseFloat(weight.toString());
                    float hightF = Float.parseFloat(height.toString());
                    if (hightF > 0) {
                        float api = hightF / 100;
                        float mbi = weightF / (api * api);
                        BigDecimal b = new BigDecimal(mbi);
                        float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();  //年龄别体重指数   体重指数= 体重/身高^2(单位m)
                        map.put("xDate", xdate);
                        map.put("yDate", f1);
                        map.put("flag", 1);

                        try {
                            paramMap.put("values", f1);
                            paramMap.put("type", Constants.DEVELOPPROJECT_AGEFORWH);
                            List<Map<String, Object>> list = getGrowthResult(ageType, paramMap, patient);
                            map.put("result", JSON.toJSONString(list));
                        } catch (Exception e) {
                            logger.error("计算百分位有误", e);
                        }
                        bmis.add(map);
                    }
                }
                paramMap.remove("values");
                paramMap.remove("type");
            } else {
                if (StringUtils.isEmpty(valueFlag)) {
                    map = new HashMap<String, Object>();
                    map.put("xDate", xdate);
                    map.put("yDate", paramMap.get("values"));
                    map.put("flag", 1);
                    try {
                        List<Map<String, Object>> list = getGrowthResult(ageType, paramMap, patient);
                        map.put("result", JSON.toJSONString(list));
                    } catch (Exception e) {
                        logger.error("计算百分位有误", e);
                    }

                    if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        weights.add(map);
                    } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        hights.add(map);
                    } else {
                        throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "type值不符合定义类型");
                    }
                }
            }
        }

        if (!CollectionUtils.isEmpty(growthDetailsList)) {
            for (int j = 0; j < growthDetailsList.size(); j++) {
                growthDetailsMap = growthDetailsList.get(j);
                map = new HashMap<String, Object>();
                int flag = 0;//是否当前记录
                if (StringUtils.isEmpty(type)) {
                    if (growthDetailsMap.get("growthRecordId").equals(paramMap.get("growthRecordId"))) {
                        //当前记录
                        flag = 1;
                        xdate = endTime / yearDay;
                    } else {
                        if (testTime.equals(growthDetailsMap.get("testTime"))) {
                            continue;
                        }

                        //计算每次记录的 X轴
                        testTimeHis = growthDetailsMap.get("testTime");
                        endTimeHis = (DateUtil.getDate_8(testTimeHis.toString()).getTime() - birthLong) / (1000 * 60 * 60 * 24);
                        xdate = endTimeHis / yearDay;
                    }
                } else {// 上传记录日期和查询出有重复的 日期的 去掉查出来的记录
                    if (testTime.equals(growthDetailsMap.get("testTime").toString())) {
                        continue;
                    }
                    testTimeHis = growthDetailsMap.get("testTime");
                    endTimeHis = (DateUtil.getDate_8(testTimeHis.toString()).getTime() - birthLong) / (1000 * 60 * 60 * 24);
                    endTimeHis = patient.getPregnancyDay() + endTimeHis;  //实际孕周+实际出生天数
                    xdate = endTimeHis / yearDay;
                }

                map.put("xDate", xdate);
                map.put("flag", flag);
                map.put("yDate", growthDetailsMap.get("weight"));

                String result = "";
                if (null != growthDetailsMap.get("result")) {
                    try {
                        result = JSON.parseObject(growthDetailsMap.get("result").toString()).getString("weightResult");
                        map.put("result", result);
                    } catch (Exception e) {
                        logger.error("5月以上曲线结果 获取记录结果error", e);
                    }
                }

                weights.add(map);

                map = new HashMap<String, Object>();
                map.put("xDate", xdate);
                map.put("yDate", growthDetailsMap.get("hight"));
                map.put("flag", flag);

                if (null != growthDetailsMap.get("result")) {
                    try {
                        result = JSON.parseObject(growthDetailsMap.get("result").toString()).getString("heightResult");
                        map.put("result", result);
                    } catch (Exception e) {
                        logger.error("fenton曲线结果 获取记录结果error", e);
                    }
                }
                hights.add(map);

                map = new HashMap<String, Object>();
                if (null != growthDetailsMap.get("weight") && null != growthDetailsMap.get("hight")) {
                    float weight = Float.parseFloat(growthDetailsMap.get("weight").toString());
                    float hight = Float.parseFloat(growthDetailsMap.get("hight").toString());
                    if (hight > 0) {
                        float api = hight / 100;
                        float mbi = weight / (api * api);
                        BigDecimal b = new BigDecimal(mbi);
                        float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();  //年龄别体重指数   体重指数= 体重/身高^2(单位m)
                        map.put("xDate", xdate);
                        map.put("yDate", f1);
                        map.put("flag", flag);
                        bmis.add(map);
                    }
                }
            }
        }

        weightMap.put("growthrecord", weights);
        lengthMap.put("growthrecord", hights);
        bmiMap.put("growthrecord", bmis);
        //先从缓存查询  没有再查询数据库
        Jedis jedis = null;

        Map<String, Object> weightMapSD = null;
        Map<String, Object> lengthMapSD = null;
        Map<String, Object> bmiMapSD = null;

        try {
            jedis = jedisPool.getResource();
            jedis.select(Constants.REDIS_DB_INDEX_EVALUATION);
            String str = "";

            if (patient.getGender().equals(Constants.GENDER_FOR_FEMALE)) {
                redisKey += ":GIRLS";
            } else {
                redisKey += ":BOYS";
            }
            str = jedis.get(Constants.GROWTH_KEY_WEIGHT + redisKey);
            if (!StringUtils.isEmpty(str)) {
                weightMapSD = JSONObject.parseObject(str);
            }
            str = jedis.get(Constants.GROWTH_KEY_LENGTH + redisKey);
            if (!StringUtils.isEmpty(str)) {
                lengthMapSD = JSONObject.parseObject(str);
            }

            str = jedis.get(Constants.GROWTH_KEY_BMI + redisKey);
            if (!StringUtils.isEmpty(str)) {
                bmiMapSD = JSONObject.parseObject(str);
            }

            if (bmiMapSD == null || lengthMapSD == null || weightMapSD == null) {
                //有一个为空 则从数据库查询
                weightMapSD = new HashMap<String, Object>();
                lengthMapSD = new HashMap<String, Object>();
                bmiMapSD = new HashMap<String, Object>();

                List<Map<String, Object>> standardList = new ArrayList<Map<String, Object>>();
                Map<String, Object> standardParam = new HashMap<String, Object>();

                //5到19岁 月龄的数据
                standardParam.put("ageMonth", 228); //50周
                standardParam.put("gender", patient.getGender());
                standardParam.put("standardId", Constants.WHO_STANDARD_ID_FIVEYEAR);//标准曲线版本
                standardParam.put("standardType", Constants.WHO_STANDARD_TYPE_PERCENT);
                if (Constants.GROWTH_SCORE_ZSCORE.equals(scoreType)) {//如果计算zscore 则传zscore类型
                    standardParam.put("standardType", Constants.WHO_STANDARD_TYPE_SCORE);
                }

                standardList = familyReportDAO.selectStandardList(standardParam);
                if (CollectionUtils.isEmpty(standardList)) {
                    throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_GROWTHS_STANDARD_FENTON_NOT_EXIST, "5岁生长发育WHO标准数据不存在");
                }
                //数据曲线处理
                processGrowthFiveData(flagType, scoreType, patient, weightMapSD, lengthMapSD,
                        bmiMapSD, standardList);

                jedis.set(Constants.GROWTH_KEY_WEIGHT + redisKey, JSONObject.toJSONString(weightMapSD));
                jedis.set(Constants.GROWTH_KEY_LENGTH + redisKey, JSONObject.toJSONString(lengthMapSD));
                jedis.set(Constants.GROWTH_KEY_BMI + redisKey, JSONObject.toJSONString(bmiMapSD));
            }

        } catch (Exception jex) {
            logger.error("redis连接异常..." + jex.getMessage());
            throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_REDIS_CONNECT_ERROR, "Redis缓存连接失败!"));
        } finally {
            if (null != jedis) {
                try {
                    jedis.close();
                    logger.warn("close redis connection...");
                } catch (Exception ex) {
                    ex.printStackTrace();
                    throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_REDIS_CONNECT_CLOSE_FAILED,
                            "Redis缓存关闭失败!"));
                }
            }
        }

        weightMap.putAll(weightMapSD);
        lengthMap.putAll(lengthMapSD);
        bmiMap.putAll(bmiMapSD);

        ArrayList<Map<String, Object>> rsp = new ArrayList<Map<String, Object>>();
        Map<String, Object> rspMap = new HashMap<String, Object>();

        rspMap = new HashMap<String, Object>();
        rspMap.put("curvedata", weightMap);
        rspMap.put("type", Constants.DEVELOPPROJECT_WEIGHT);
        rspMap.put("standardName", Constants.WHO_STANDARD_FIVEYEAR_NAME);
        rsp.add(rspMap);

        rspMap = new HashMap<String, Object>();
        rspMap.put("curvedata", lengthMap);
        rspMap.put("type", Constants.DEVELOPPROJECT_LENGTH);
        rspMap.put("standardName", Constants.WHO_STANDARD_FIVEYEAR_NAME);
        rsp.add(rspMap);

        //bmi
        rspMap = new HashMap<String, Object>();
        rspMap.put("curvedata", bmiMap);
        rspMap.put("type", Constants.DEVELOPPROJECT_AGEFORWH);
        rspMap.put("standardName", Constants.WHO_STANDARD_FIVEYEAR_NAME);
        rsp.add(rspMap);

        return rsp;
    }

    private void processFentonData(String flagType, String scoreType,
                                   Map<String, Object> weightMapSD, Map<String, Object> lengthMapSD,
                                   Map<String, Object> headMapSD,
                                   List<Map<String, Object>> standardList) {
        Map<String, Object> temp = null;
        ArrayList<Object[]> SD2neg = new ArrayList<Object[]>();
        ArrayList<Object[]> SD1neg = new ArrayList<Object[]>();
        ArrayList<Object[]> SD3neg = new ArrayList<Object[]>();
        ArrayList<Object[]> SD4neg = new ArrayList<Object[]>();
        ArrayList<Object[]> SD0 = new ArrayList<Object[]>();
        ArrayList<Object[]> SD1 = new ArrayList<Object[]>();
        ArrayList<Object[]> SD2 = new ArrayList<Object[]>();
        ArrayList<Object[]> SD3 = new ArrayList<Object[]>();
        ArrayList<Object[]> SD4 = new ArrayList<Object[]>();
        ArrayList<Object[]> P15 = new ArrayList<Object[]>();
        ArrayList<Object[]> P85 = new ArrayList<Object[]>();

        ArrayList<Object[]> weightSD2neg = new ArrayList<Object[]>();
        ArrayList<Object[]> weightSD1neg = new ArrayList<Object[]>();
        ArrayList<Object[]> weightSD3neg = new ArrayList<Object[]>();
        ArrayList<Object[]> weightSD4neg = new ArrayList<Object[]>();
        ArrayList<Object[]> weightSD0 = new ArrayList<Object[]>();
        ArrayList<Object[]> weightSD1 = new ArrayList<Object[]>();
        ArrayList<Object[]> weightSD2 = new ArrayList<Object[]>();
        ArrayList<Object[]> weightSD3 = new ArrayList<Object[]>();
        ArrayList<Object[]> weightSD4 = new ArrayList<Object[]>();
        ArrayList<Object[]> weightP15 = new ArrayList<Object[]>();
        ArrayList<Object[]> weightP85 = new ArrayList<Object[]>();

        ArrayList<Object[]> headSD2neg = new ArrayList<Object[]>();
        ArrayList<Object[]> headSD1neg = new ArrayList<Object[]>();
        ArrayList<Object[]> headSD3neg = new ArrayList<Object[]>();
        ArrayList<Object[]> headSD4neg = new ArrayList<Object[]>();
        ArrayList<Object[]> headSD0 = new ArrayList<Object[]>();
        ArrayList<Object[]> headSD1 = new ArrayList<Object[]>();
        ArrayList<Object[]> headSD2 = new ArrayList<Object[]>();
        ArrayList<Object[]> headSD3 = new ArrayList<Object[]>();
        ArrayList<Object[]> headSD4 = new ArrayList<Object[]>();
        ArrayList<Object[]> headP15 = new ArrayList<Object[]>();
        ArrayList<Object[]> headP85 = new ArrayList<Object[]>();

        for (int i = 0; i < standardList.size(); i++) {
            temp = standardList.get(i);
            //
            long age = Long.parseLong(temp.get("age").toString());
            if (age % 2 == 0) {
                //
            } else {
                continue;
            }

            if (Constants.DEVELOPPROJECT_HEAD.equals(temp.get("developProject_id"))) {
                headSD2neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD2NEG").toString())});
                headSD1neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD1NEG").toString())});
                headSD3neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD3NEG").toString())});
                headSD0.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD0").toString())});
                headSD1.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD1").toString())});
                headSD2.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD2").toString())});
                headSD3.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD3").toString())});

                if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                    headSD4neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD4NEG").toString())});
                    headSD4.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD4").toString())});
                    headP15.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("P15").toString())});
                    headP85.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("P85").toString())});
                }

            } else if (Constants.DEVELOPPROJECT_LENGTH.equals(temp.get("developProject_id"))) {
                SD2neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD2NEG").toString())});
                SD1neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD1NEG").toString())});
                SD3neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD3NEG").toString())});
                SD0.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD0").toString())});
                SD1.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD1").toString())});
                SD2.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD2").toString())});
                SD3.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD3").toString())});
                if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                    SD4neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD4NEG").toString())});
                    SD4.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD4").toString())});
                    P15.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("P15").toString())});
                    P85.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("P85").toString())});
                }
            } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(temp.get("developProject_id"))) {
                weightSD2neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD2NEG").toString())});
                weightSD1neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD1NEG").toString())});
                weightSD3neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD3NEG").toString())});
                weightSD0.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD0").toString())});
                weightSD1.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD1").toString())});
                weightSD2.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD2").toString())});
                weightSD3.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD3").toString())});
                if (Constants.GROWTH_SCORE_PERCENT.equals(scoreType)) {//百分位才有此数据
                    weightSD4.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD4").toString())});
                    weightP15.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("P15").toString())});
                    weightP85.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("P85").toString())});
                    weightSD4neg.add(new Object[]{(float) age / 7, Float.parseFloat(temp.get("SD4NEG").toString())});
                }
            }
        }

//      int yMin = 0;
//		if(Constants.NUMBER_TYPE_FIVE_CURVES.equals(flagType)){//5条
        weightMapSD.put("yMax", 7.5);  //
        headMapSD.put("yMax", 60);
        lengthMapSD.put("yMax", 60);
        weightMapSD.put("yMin", 0);
        headMapSD.put("yMin", 15);
        lengthMapSD.put("yMin", 15);
//		}

        //获取9条曲线数据  //展示7条
        weightMapSD.put("SD0", weightSD0);
        weightMapSD.put("SD1", weightSD1);
        weightMapSD.put("SD2", weightSD2);
        weightMapSD.put("SD3", weightSD3);
        weightMapSD.put("SD4", weightSD4);
        weightMapSD.put("SD1eng", weightSD1neg);
        weightMapSD.put("SD2eng", weightSD2neg);
        weightMapSD.put("SD3eng", weightSD3neg);
        weightMapSD.put("SD4eng", weightSD4neg);
        weightMapSD.put("P15", weightP15);
        weightMapSD.put("P85", weightP85);

        lengthMapSD.put("SD0", SD0);
        lengthMapSD.put("SD1", SD1);
        lengthMapSD.put("SD2", SD2);
        lengthMapSD.put("SD3", SD3);
        lengthMapSD.put("SD4", SD4);
        lengthMapSD.put("SD1eng", SD1neg);
        lengthMapSD.put("SD2eng", SD2neg);
        lengthMapSD.put("SD3eng", SD3neg);
        lengthMapSD.put("SD4eng", SD4neg);
        lengthMapSD.put("P15", P15);
        lengthMapSD.put("P85", P85);

        headMapSD.put("SD0", headSD0);
        headMapSD.put("SD1", headSD1);
        headMapSD.put("SD2", headSD2);
        headMapSD.put("SD3", headSD3);
        headMapSD.put("SD4", headSD4);
        headMapSD.put("SD1eng", headSD1neg);
        headMapSD.put("SD2eng", headSD2neg);
        headMapSD.put("SD3eng", headSD3neg);
        headMapSD.put("SD4eng", headSD4neg);
        headMapSD.put("P15", headP15);
        headMapSD.put("P85", headP85);
    }

    @Override
    public Map<String, Object> getGrowthFentonPercent(
            Map<String, Object> paramMap, Patient patient) throws Exception {
        Map<String, Object> rspMap = new HashMap<String, Object>();
//		String flag = (String)paramMap.get("flag");
        String type = (String) paramMap.get("type");
        Map<String, Object> userPara = new HashMap<String, Object>();
        userPara.put("userId", paramMap.get("userId"));
        userPara.put("tenantId", paramMap.get("tenantId"));
//		map.put("status","1"));
        if (null == patient) {
            patient = patientdao.selectById(userPara);
        }
        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "生长发育评估记录患者信息不存在");
        }

        String birthday = patient.getBirthday();
        Integer pregnancyDay = patient.getPregnancyDay();
        Long birthLong = ToolUtils.getCorrect(birthday, null);//生日时间戳

        String testTime = (String) paramMap.get("testTime");
        long ageDay = 0L;
        if (StringUtils.isEmpty(testTime)) {
            ageDay = (new Date().getTime() - birthLong) / (1000 * 60 * 60 * 24);
        } else {
            ageDay = (DateUtil.getDate_8(testTime).getTime() - birthLong) / (1000 * 60 * 60 * 24);
        }

        if (patient.getPregnancyDay() == 0) { //孕周==0 ，没有填  默认为40周
            ageDay = 280 + ageDay;  //正常小孩 走生长发育曲线
        } else {
            ageDay = pregnancyDay + ageDay;
        }

        //查询FENTON标准数据
        Map<String, Object> whoMap = new HashMap<String, Object>();
        whoMap.put("age", ageDay);
        whoMap.put("gender", patient.getGender());
        whoMap.put("standardId", Constants.WHO_STANDARD_ID);
        whoMap.put("standardType", Constants.FENTON_STANDARD_TYPE_PERCENT);
        if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
            whoMap.put("developProjectId", Constants.DEVELOPPROJECT_HEAD);
        } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
            whoMap.put("developProjectId", Constants.DEVELOPPROJECT_WEIGHT);
        } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
            whoMap.put("developProjectId", Constants.DEVELOPPROJECT_LENGTH);
        } else {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "type值不符合要求");
        }
        whoMap.put("length", 0);
        //返回超过年龄 无标准数据

        String percent = "";
        String sumary = "";
        String level = "";
        List<Map<String, Object>> whoMaplist = familyReportDAO.selectDevelopStandardForWho(whoMap);
        if (!CollectionUtils.isEmpty(whoMaplist)) {//
//			double p1 = (double) whoMaplist.get(0).get("SD4NEG");
            double p3 = (double) whoMaplist.get(0).get("SD3NEG");
            double p10 = (double) whoMaplist.get(0).get("SD2NEG");
            double p25 = (double) whoMaplist.get(0).get("SD1NEG");
            double p50 = (double) whoMaplist.get(0).get("SD0");
            double p75 = (double) whoMaplist.get(0).get("SD1");
            double p90 = (double) whoMaplist.get(0).get("SD2");
            double p97 = (double) whoMaplist.get(0).get("SD3");
//			double p99 = (double)whoMaplist.get(0).get("SD4");

            double p15 = (double) whoMaplist.get(0).get("P15");
            double p85 = (double) whoMaplist.get(0).get("P85");

            double value = Double.parseDouble(String.valueOf(paramMap.get("values")));

            // 50为分隔   50以上  > && <=    50以下 >= && <
				/*if(value < p3){
					percent = "<3%";
				}else if(value>=p3 && value < p10){
					percent = "3%~10%";
				}else if(value>=p10 && value < p15){
					percent = "10%~15%";
				}else if(value>=p15 && value < p25){
					percent = "15%~25%";
				}else if(value>=p25 && value < p50){
					percent = "25%~50%";
				}else if(value>=p50 && value <=p75){
					percent = "50%~75%";
				}else if(value>p75 && value <=p85){
					percent = "75%~85%";
				}else if(value>p85 && value <=p90){
					percent = "85%~90%";
				}else if(value>p90 && value <= p97){
					percent = "90%~97%";
				}else if(value>p97){
					percent = ">97%";
				}*/
            if (value < p3) {
                percent = "<3%";
                percent = 3 + Math.round(((value - p3)/100)) + "%";
                level = Constants.LEVELH;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headH;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightH;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightH;
                }
            } else if (value >= p3 && value < p10) {
                level = Constants.LEVELG;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headG;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightG;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightG;
                }
                percent = "3%~10%";
                double a = (p10 - p3) / 7;
                double b = value - p3;
                double c = b / a;
                percent = Math.round(3 + c) + "%";
            } else if (value >= p10 && value < p15) {
                level = Constants.LEVELF;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headF;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightF;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightF;
                }
                percent = "10%~15%";
                double a = (p15 - p10) / 5;
                double b = value - p10;
                double c = b / a;
                percent = Math.round(10 + c) + "%";
            } else if (value >= p15 && value < p25) {
                level = Constants.LEVELF;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headF;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightF;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightF;
                }
                percent = "15%~25%";
                double a = (p25 - p15) / 10;
                double b = value - p15;
                double c = b / a;
                percent = Math.round(15 + c) + "%";
            } else if (value >= p25 && value < p50) {
                level = Constants.LEVELE;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headE;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightE;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightE;
                }
                percent = "25%~50%";
                double a = (p50 - p25) / 25;
                double b = value - p25;
                double c = b / a;
                percent = Math.round(25 + c) + "%";
            } else if (value >= p50 && value <= p75) {
                level = Constants.LEVELD;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headD;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightD;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightD;
                }
                percent = "50%~75%";
                double a = (p75 - p50) / 25;
                double b = value - p50;
                double c = b / a;
                percent = Math.round(50 + c) + "%";
            } else if (value > p75 && value <= p85) {
                level = Constants.LEVELC;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headC;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightC;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightC;
                }
                percent = "75%~85%";
                double a = (p85 - p75) / 10;
                double b = value - p75;
                double c = b / a;
                percent = Math.round(75 + c) + "%";
            } else if (value > p85 && value <= p90) {
                level = Constants.LEVELC;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headC;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightC;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightC;
                }
                percent = "85%~90%";
                double a = (p90 - p85) / 5;
                double b = value - p85;
                double c = b / a;
                percent = Math.round(85 + c) + "%";
            } else if (value > p90 && value <= p97) {
                level = Constants.LEVELB;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headB;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightB;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightB;
                }
                percent = "90%~97%";
                double a = (p97 - p90) / 7;
                double b = value - p90;
                double c = b / a;
                percent = Math.round(90 + c) + "%";
            } else if (value > p97) {
                level = Constants.LEVELA;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headA;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightA;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightA;
                }
                percent = ">97%";
                percent = 97 + Math.round(((value - p97)/100)) + "%";
            }
        } else {
//			rspMap.put("percentiles","");
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_GROWTHS_STANDARD_WHO_AGE_OVER_MAXAGE, "该用户不在Fenton评测年龄范围内");
        }
        rspMap.put("percentiles", percent);
//		rspMap.put("time","2013");
        rspMap.put("level", level);
        rspMap.put("sumary", sumary);
        return rspMap;
    }

    @Override
    public Map<String, Object> getGrowthFentonScore(Map<String, Object> paramMap, Patient patient)
            throws Exception {
        Map<String, Object> rspMap = new HashMap<String, Object>();
//		String flag = (String)paramMap.get("flag");
        String type = (String) paramMap.get("type");
        Map<String, Object> userPara = new HashMap<String, Object>();
        userPara.put("userId", paramMap.get("userId"));
        userPara.put("tenantId", paramMap.get("tenantId"));
//		map.put("status","1"));
        if (null == patient) {
            patient = patientdao.selectById(userPara);
        }

        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "生长发育评估记录患者信息不存在");
        }

        String birthday = patient.getBirthday();
        Integer pregnancyDay = patient.getPregnancyDay();
        Long birthLong = ToolUtils.getCorrect(birthday, null);//生日时间戳

        String testTime = (String) paramMap.get("testTime");
        long ageDay = 0L;
        if (StringUtils.isEmpty(testTime)) {
            ageDay = (new Date().getTime() - birthLong) / (1000 * 60 * 60 * 24);
        } else {
            ageDay = (DateUtil.getDate_8(testTime).getTime() - birthLong) / (1000 * 60 * 60 * 24);
        }

        if (patient.getPregnancyDay() == 0) { //孕周==0 ，没有填  默认为40周
            ageDay = 280 + ageDay;  //正常小孩 走生长发育曲线
        } else {
            ageDay = pregnancyDay + ageDay;
        }

        //查询who标准数据
        Map<String, Object> whoMap = new HashMap<String, Object>();
        whoMap.put("age", ageDay);
        whoMap.put("gender", patient.getGender());
        whoMap.put("standardId", Constants.WHO_STANDARD_ID);
        whoMap.put("standardType", Constants.FENTON_STANDARD_TYPE_SCORE);
        if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
            whoMap.put("developProjectId", Constants.DEVELOPPROJECT_HEAD);
        } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
            whoMap.put("developProjectId", Constants.DEVELOPPROJECT_WEIGHT);
        } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
            whoMap.put("developProjectId", Constants.DEVELOPPROJECT_LENGTH);
        } else {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "type值不符合要求");
        }
        whoMap.put("length", 0);
        //返回超过年龄 无标准数据

        String zscore = "";
        String sumary = "";
        String level = "";
        List<Map<String, Object>> whoMaplist = familyReportDAO.selectDevelopStandardForWho(whoMap);
        if (!CollectionUtils.isEmpty(whoMaplist)) {//
//			double sd4neg = (double) whoMaplist.get(0).get("SD4NEG");
            double sd3neg = (double) whoMaplist.get(0).get("SD3NEG");
            double sd2neg = (double) whoMaplist.get(0).get("SD2NEG");
            double sd1neg = (double) whoMaplist.get(0).get("SD1NEG");
            double sd0 = (double) whoMaplist.get(0).get("SD0");
            double sd1 = (double) whoMaplist.get(0).get("SD1");
            double sd2 = (double) whoMaplist.get(0).get("SD2");
            double sd3 = (double) whoMaplist.get(0).get("SD3");
//			double sd4 = (double)whoMaplist.get(0).get("SD4");

            double value = Double.parseDouble(String.valueOf(paramMap.get("values")));

            // 50为分隔   50以上  > && <=    50以下 >= && <
				/*if(value < sd3neg ){
					zscore = "<-3";
				}else if(value >= sd3neg && value < sd2neg){
					zscore = "-3~-2";
				}else if(value >= sd2neg && value < sd1neg){
					zscore = "-2~-1";
				}else if(value>=sd1neg && value < sd0){
					zscore = "-1~0";
				}else if(value>=sd0 && value <= sd1){
					zscore = "0~1";
				}else if(value>=sd1 && value <=sd2){
					zscore = "1~2";
				}else if(value>sd2 && value <=sd3){
					zscore = "2~3";
				}else if(value>sd3){
					zscore = ">3";
				}*/
            if (value < sd3neg) {
                zscore = "<-3";
                level = Constants.LEVELH;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headH;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightH;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightH;
                }
            } else if (value >= sd3neg && value < sd2neg) {
                level = Constants.LEVELG;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headG;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightG;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightG;
                }
                zscore = "-3~-2";
            } else if (value >= sd2neg && value < sd1neg) {
                level = Constants.LEVELF;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headF;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightF;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightF;
                }
                zscore = "-2~-1";
            } else if (value >= sd1neg && value < sd0) {
                level = Constants.LEVELE;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headE;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightE;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightE;
                }
                zscore = "-1~0";
            } else if (value >= sd0 && value <= sd1) {
                level = Constants.LEVELD;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headD;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightD;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightD;
                }
                zscore = "0~1";
            } else if (value >= sd1 && value <= sd2) {
                level = Constants.LEVELC;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headC;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightC;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightC;
                }
                zscore = "1~2";
            } else if (value > sd2 && value <= sd3) {
                level = Constants.LEVELB;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headB;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightB;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightB;
                }
                zscore = "2~3";
            } else if (value > sd3) {
                level = Constants.LEVELA;
                if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                    sumary = Constants.headA;
                } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                    sumary = Constants.weightA;
                } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    sumary = Constants.heightA;
                }
                zscore = ">3";
            }
        } else {
//			rspMap.put("percentiles","");
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_GROWTHS_STANDARD_WHO_AGE_OVER_MAXAGE, "该用户不在Fenton评测年龄范围内！");
        }
        rspMap.put("zscore", zscore);
//		rspMap.put("time","2013");
        rspMap.put("sumary", sumary);
        rspMap.put("level", level);
        return rspMap;
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<String> getGrowthGuideListNew(List<Map<String, Object>> curvadataList, Map<String, Object> param) throws Exception {
        logger.info("in getGrowthGuideListNew");
        List<String> guidelist = new ArrayList<String>();
        //查询 18岁 身高记录
        String scoreType = (String) param.get("scoreType");

        Map<String, Object> userPara = new HashMap<String, Object>();
        userPara.put("userId", param.get("userId"));
        userPara.put("tenantId", param.get("tenantId"));
        Patient patient = patientdao.selectById(userPara);
        if (null == patient) {
            throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_PATIENT_NOT_EXIST,
                    "生长发育评估记录患者信息不存在");
        }

        Map<String, Object> whoMap = new HashMap<String, Object>();
        whoMap.put("ageMonth", 216);
        whoMap.put("standardId", Constants.WHO_STANDARD_ID_FIVEYEAR);
        whoMap.put("standardType", Constants.WHO_STANDARD_TYPE_PERCENT);
        if (Constants.GROWTH_SCORE_ZSCORE.equals(scoreType)) {//如果计算zscore 则传zscore类型
            whoMap.put("standardType", Constants.WHO_STANDARD_TYPE_SCORE);
        }
        whoMap.put("gender", patient.getGender());
        whoMap.put("developProjectId", Constants.DEVELOPPROJECT_LENGTH);
        whoMap.put("length", 0);

        String lenght = "";
        List<Map<String, Object>> whoMaplist = familyReportDAO.selectDevelopStandardForWho(whoMap);
        if (!CollectionUtils.isEmpty(whoMaplist)) {//
            lenght = whoMaplist.get(0).get("SD0").toString();
        }

        String testTime = (String) param.get("testTime");//身高体重查询曲线  必须传入监测时间
        if (null == testTime) {
            testTime = DateUtil.getDate_8(new Date());
        }
        Date testdate = DateUtil.getDate_8(testTime.toString());
        Long birthLong = ToolUtils.getCorrect(patient.getBirthday(), patient.getPregnancyDay());//生日时间戳

        long ageDay = (testdate.getTime() - birthLong) / (1000 * 60 * 60 * 24);
        long ageMonth = (long) (ageDay / 30.4);

        guidelist.add("对应标准成年身高是 " + lenght + "cm.");

        Jedis jedis = null;
        try {
            jedis = jedisPool.getResource();
            jedis.select(Constants.REDIS_DB_INDEX_EVALUATION);
            if (CollectionUtils.isEmpty(curvadataList)) {
                return guidelist;
            }

            for (int i = 0; i < curvadataList.size(); i++) {
                String level = "";
                String key = "";
                Object type = curvadataList.get(i).get("type");
                if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)
                        || Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                    if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                        key = Constants.GROWTH_GUIDE_WEIGHT + ageMonth;
                    }
                    if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                        key = Constants.GROWTH_GUIDE_LENGTH + ageMonth;
                    }
                    if (null != curvadataList.get(i).get("curvedata")) {
                        Object jsonObj = ((Map<String, Object>) curvadataList.get(i).get("curvedata")).get("growthrecord");
                        if (null != jsonObj && jsonObj instanceof List<?>) {
                            List<Map<String, Object>> list = (List<Map<String, Object>>) jsonObj;
                            for (int j = 0; j < list.size(); j++) {
                                if (null != list.get(j).get("flag") && "1".equals(list.get(j).get("flag").toString())) {
                                    Object result = list.get(j).get("result");
                                    if (!StringUtils.isEmpty(result)) {
                                        JSONArray arr = JSON.parseArray(result.toString());
                                        level = arr.getJSONObject(0).getString("level");
                                    }

                                }
                            }
                        }
                    }
                } else {
                    continue;
                }

                if (!StringUtils.isEmpty(level)) {
                    String jsonStr = jedis.hget(Constants.FOLLOW_EVALUATION_GROWTH_GUIDE_KEY, key);
                    if (StringUtils.isEmpty(jsonStr)) {
                        Map<String, Object> paramMap = new HashMap<String, Object>();
                        paramMap.put("field", Constants.FOLLOW_EVALUATION_GROWTH_GUIDE_KEY);
                        paramMap.put("key", key);
                        FuAssessMentPosition position = followEvaluationDao.selectAssessMentPosition(paramMap);
                        if (null != position) {
                            jsonStr = position.getValue();
                            jedis.hset(Constants.FOLLOW_EVALUATION_GROWTH_GUIDE_KEY, key, jsonStr);
                        }
                    }

                    if (!StringUtils.isEmpty(jsonStr)) {
                        JSONObject json = JSON.parseObject(jsonStr);
                        String guideStr = json.getString(level);
                        if (!StringUtils.isEmpty(guideStr)) {
                            guidelist.add(guideStr);
                        }
                    }
                }
            }
        } catch (JedisConnectionException jex) {
            logger.error("redis连接异常..." + jex.getMessage());
        } finally {
            if (null != jedis) {
                try {
                    jedis.close();
                    logger.warn("close redis connection...");
                } catch (Exception ex) {
                    logger.error("redis连接异常..." + ex.getMessage(), ex);
                }
            }
        }
        return guidelist;
    }

    @Override
    public void deleteGrowthRecordById(String recordId) throws Exception {

        if (!StringUtils.isEmpty(recordId)) {
            Map params = new HashMap();
            params.put("recordId", recordId);
            familyReportDAO.deleteGrowthRecord(params);
        }


    }

    //判断早产儿量表使用情况
    private boolean getScale(Patient patient, Date testdate, String ageType) throws Exception {
        ageType = ageType == null ? Constants.GROWTH_AGE_TYPE_CORRECT : ageType;
        int tempDay = ageType.equals(Constants.GROWTH_AGE_TYPE_CORRECT) ? patient.getPregnancyDay() : 280;
        if ((patient.getPregnancyDay() < 259) &&
                DateUtil.daysBetween(DateUtil.getDate(patient.getBirthday()), testdate) + tempDay <= 350) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 计算出生P值。
     *
     * @param paraMap type："00001"体重，"00002"身长，"00003"头围；
     *                gender："N"男,"F"女；
     *                value：体格数据值。
     *                age：实际年龄（单位：天）。
     *                pweek：孕周（单位：周）。
     *                pday：孕周（单位：天）。
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> getPercentiles(Map<String, Object> paraMap) throws Exception {
        final String type = (String) paraMap.get("type");
        final String gender = (String) paraMap.get("gender");
        double value = Double.parseDouble(String.valueOf(paraMap.get("value")));
        int age = Integer.parseInt(String.valueOf(paraMap.get("age")));
        final int pweek = Integer.parseInt(String.valueOf(paraMap.get("pweek")));
        final int pday = Integer.parseInt(String.valueOf(paraMap.get("pday")));

        Map<String, Object> retMap = new HashMap<String, Object>();
        Map<String, Object> whoMap = new HashMap<String, Object>();
        if (pweek < 37) {
            whoMap.put("standardType", Constants.FENTON_STANDARD_TYPE_PERCENT);
            retMap.put("dataset", "WHO2013_FENTON");
            age = age + pweek * 7 + pday;
        } else {
            whoMap.put("standardType", Constants.WHO_STANDARD_TYPE_PERCENT);
            retMap.put("dataset", "WHO2013");
        }
        if (type.equalsIgnoreCase(Constants.DEVELOPPROJECT_WEIGHT)) {
            value = value / 1000;
        }

        String percent = "";
        //查询WHO标准数据.
        whoMap.put("age", age);
        whoMap.put("gender", gender);
        whoMap.put("standardId", Constants.WHO_STANDARD_ID);
        if (true) {
            if (Constants.DEVELOPPROJECT_HEAD.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_HEAD);
            } else if (Constants.DEVELOPPROJECT_WEIGHT.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_WEIGHT);
            } else if (Constants.DEVELOPPROJECT_LENGTH.equals(type)) {
                whoMap.put("developProjectId", Constants.DEVELOPPROJECT_LENGTH);
            } else {
                throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "type值不符合要求");
            }
            whoMap.put("length", 0);
            List<Map<String, Object>> whoMaplist = familyReportDAO.selectDevelopStandardForWho(whoMap);
            if (!CollectionUtils.isEmpty(whoMaplist)) {
                double p1 = (double) whoMaplist.get(0).get("SD4NEG");
                double p3 = (double) whoMaplist.get(0).get("SD3NEG");
                double p10 = (double) whoMaplist.get(0).get("SD2NEG");
                double p25 = (double) whoMaplist.get(0).get("SD1NEG");
                double p50 = (double) whoMaplist.get(0).get("SD0");
                double p75 = (double) whoMaplist.get(0).get("SD1");
                double p90 = (double) whoMaplist.get(0).get("SD2");
                double p97 = (double) whoMaplist.get(0).get("SD3");
                double p99 = (double) whoMaplist.get(0).get("SD4");

                if (value < p1) {
                    percent = "<1%";
                } else if (value >= p1 && value < p3) {
                    percent = "1%~3%";
                    double a = (p3 - p1) / 2;
                    double b = value - p1;
                    double c = b / a;
                    percent = Math.round(1 + c) + "%";
                } else if (value >= p3 && value < p10) {
                    percent = "3%~10%";
                    double a = (p10 - p3) / 7;
                    double b = value - p3;
                    double c = b / a;
                    percent = Math.round(3 + c) + "%";
                } else if (value >= p10 && value < p25) {
                    percent = "10%~25%";
                    double a = (p25 - p10) / 15;
                    double b = value - p10;
                    double c = b / a;
                    percent = Math.round(10 + c) + "%";
                }else if (value >= p25 && value < p50) {
                    percent = "25%~50%";
                    double a = (p50 - p25) / 25;
                    double b = value - p25;
                    double c = b / a;
                    percent = Math.round(25 + c) + "%";
                } else if (value >= p50 && value <= p75) {
                    percent = "50%~75%";
                    double a = (p75 - p50) / 25;
                    double b = value - p50;
                    double c = b / a;
                    percent = Math.round(50 + c) + "%";
                } else if (value > p75 && value <= p90) {
                    percent = "75%~90%";
                    double a = (p90 - p75) / 15;
                    double b = value - p75;
                    double c = b / a;
                    percent = Math.round(75 + c) + "%";
                } else if (value > p90 && value <= p97) {
                    percent = "90%~97%";
                    double a = (p97 - p90) / 7;
                    double b = value - p90;
                    double c = b / a;
                    percent = Math.round(90 + c) + "%";
                } else if (value > p97 && value <= p99) {
                    percent = "97%~99%";
                    double a = (p99-p97)/ 2;
                    double b = value - p97;
                    double c = b / a;
                    percent = Math.round(97 + c) + "%";
                } else if (value > p99) {
                    percent = ">99.9%";
                }

            } else {
                throw new AppException(ErrorCode.FOLLOWUP_EXCEPTION_GROWTHS_STANDARD_WHO_AGE_OVER_MAXAGE, "该用户不在评测年龄范围内！");
            }
            retMap.put("percentiles", percent);
        }

        return retMap;
    }

    /**
     * 根据2005年9市生长评价数值表，计算出生体格P值8档。
     * @param paraMap
     * @return
     */
    @Override
    public Map<String,Object> getBirthPercentiles(final Map<String,Object> paraMap) {
        Map<String,Object> retMap   = new HashMap<>();
        if (paraMap.containsKey("weightValue"))  {
            retMap.putAll(getBirthWeightPercentiles(paraMap));
        } else if (paraMap.containsKey("lengthValue"))    {
            retMap.putAll(getBirthLengthPercentiles(paraMap));
        } else if (paraMap.containsKey("headValue"))    {
            retMap.putAll(getBirthHeadPercentiles(paraMap));
        }

        return retMap;
    }

    /**
     * 根据2005年9市生长评价数值表，计算出生身长P值8档。
     * @param paraMap
     * @return
     */
    private Map<String,Object> getBirthLengthPercentiles(final Map<String,Object> paraMap)    {
        Map<String,Object> retMap   = new HashMap<>();
        final String gender = (String) paraMap.get("gender");
        double value  = Double.parseDouble(String.valueOf(paraMap.get("lengthValue")));
        String percent  = "";
        double p1=0.0,p3=0.0,p10=0.0,p25=0.0,p50=0.0,p75=0.0,p90=0.0,p97=0.0,p99=0.0;
        if (gender.equalsIgnoreCase("N"))    {
            //2005年9市出生身长cm。
            p1  = 46.3;
            p3  = 47.1;
            p10 = 48.1;
            p25 = 49.2;
            p50 = 50.4;
            p75 = 51.6;
            p90 = 52.7;
            p97 = 53.8;
            p99 = 54.6;
        } else {
            p1  = 45.8;
            p3  = 46.6;
            p10 = 47.5;
            p25 = 48.6;
            p50 = 49.7;
            p75 = 50.9;
            p90 = 51.9;
            p97 = 53.0;
            p99 = 53.8;
        }
        if (value < p1) {
            percent = "<1%";
        } else if (value >= p1 && value < p3) {
            percent = "1%~3%";
            double a = (p3 - p1) / 2;
            double b = value - p1;
            double c = b / a;
            percent = Math.round(1 + c) + "%";
        } else if (value >= p3 && value < p10) {
            percent = "3%~10%";
            double a = (p10 - p3) / 7;
            double b = value - p3;
            double c = b / a;
            percent = Math.round(3 + c) + "%";
        } else if (value >= p10 && value < p25) {
            percent = "10%~25%";
            double a = (p25 - p10) / 15;
            double b = value - p10;
            double c = b / a;
            percent = Math.round(10 + c) + "%";
        }else if (value >= p25 && value < p50) {
            percent = "25%~50%";
            double a = (p50 - p25) / 25;
            double b = value - p25;
            double c = b / a;
            percent = Math.round(25 + c) + "%";
        } else if (value >= p50 && value <= p75) {
            percent = "50%~75%";
            double a = (p75 - p50) / 25;
            double b = value - p50;
            double c = b / a;
            percent = Math.round(50 + c) + "%";
        } else if (value > p75 && value <= p90) {
            percent = "75%~90%";
            double a = (p90 - p75) / 15;
            double b = value - p75;
            double c = b / a;
            percent = Math.round(75 + c) + "%";
        } else if (value > p90 && value <= p97) {
            percent = "90%~97%";
            double a = (p97 - p90) / 7;
            double b = value - p90;
            double c = b / a;
            percent = Math.round(90 + c) + "%";
        } else if (value > p97 && value <= p99) {
            percent = "97%~99%";
            double a = (p99 - p97) / 5;
            double b = value - p97;
            double c = b / a;
            percent = Math.round(97 + c) + "%";
        } else if (value > p99) {
            percent = ">99.9%";
        }
        retMap.put("percentiles", percent);
        retMap.put("msg",   "已计算了出生身长P值；");

        return retMap;
    }

    /**
     * 根据2005年9市生长评价数值表，计算出生头围P值8档。
     * @param paraMap
     * @return
     */
    private Map<String,Object> getBirthHeadPercentiles(final Map<String,Object> paraMap)    {
        Map<String,Object> retMap   = new HashMap<>();
        final String gender = (String) paraMap.get("gender");
        double value    = Double.parseDouble(String.valueOf(paraMap.get("headValue")));
        String percent  = "";
        double p1=0.0,p3=0.0,p10=0.0,p25=0.0,p50=0.0,p75=0.0,p90=0.0,p97=0.0,p99=0.0;
        if (gender.equalsIgnoreCase("N"))    {
            //2005年9市出生头围cm。
            p1  = 31.7;
            p3  = 32.3;
            p10 = 33.0;
            p25 = 33.7;
            p50 = 34.5;
            p75 = 35.3;
            p90 = 36.0;
            p97 = 36.7;
            p99 = 37.2;
        } else {
            p1  = 31.2;
            p3  = 31.8;
            p10 = 32.5;
            p25 = 33.2;
            p50 = 34.0;
            p75 = 34.8;
            p90 = 35.5;
            p97 = 36.2;
            p99 = 36.7;
        }
        if (value < p1) {
            percent = "<1%";
        } else if (value >= p1 && value < p3) {
            percent = "1%~3%";
            double a = (p3 - p1) / 2;
            double b = value - p1;
            double c = b / a;
            percent = Math.round(1 + c) + "%";
        } else if (value >= p3 && value < p10) {
            percent = "3%~10%";
            double a = (p10 - p3) / 7;
            double b = value - p3;
            double c = b / a;
            percent = Math.round(3 + c) + "%";
        } else if (value >= p10 && value < p25) {
            percent = "10%~25%";
            double a = (p25 - p10) / 15;
            double b = value - p10;
            double c = b / a;
            percent = Math.round(10 + c) + "%";
        }else if (value >= p25 && value < p50) {
            percent = "25%~50%";
            double a = (p50 - p25) / 25;
            double b = value - p25;
            double c = b / a;
            percent = Math.round(25 + c) + "%";
        } else if (value >= p50 && value <= p75) {
            percent = "50%~75%";
            double a = (p75 - p50) / 25;
            double b = value - p50;
            double c = b / a;
            percent = Math.round(50 + c) + "%";
        } else if (value > p75 && value <= p90) {
            percent = "75%~90%";
            double a = (p90 - p75) / 15;
            double b = value - p75;
            double c = b / a;
            percent = Math.round(75 + c) + "%";
        } else if (value > p90 && value <= p97) {
            percent = "90%~97%";
            double a = (p97 - p90) / 7;
            double b = value - p90;
            double c = b / a;
            percent = Math.round(90 + c) + "%";
        } else if (value > p97 && value <= p99) {
            percent = "97%~99%";
            double a = (p99 - p97) / 5;
            double b = value - p97;
            double c = b / a;
            percent = Math.round(97 + c) + "%";
        } else if (value > p99) {
            percent = ">99.9%";
        }
        retMap.put("percentiles", percent);
        retMap.put("msg",   "已计算了出生头围P值；");

        return retMap;
    }

    /**
     * 根据2005年9市生长评价数值表，计算出生体重P值8档。
     * @param paraMap
     * @return
     */
    private Map<String,Object> getBirthWeightPercentiles(final Map<String,Object> paraMap)   {
        Map<String, Object> retMap  = new HashMap<String, Object>();
        final String gender = (String) paraMap.get("gender");
        double value    = Double.parseDouble(String.valueOf(paraMap.get("weightValue")));
        String percent  = "";
        double p1=0.0,p3=0.0,p10=0.0,p25=0.0,p50=0.0,p75=0.0,p90=0.0,p97=0.0,p99=0.0;
        if (gender.equalsIgnoreCase("N"))    {
            //2005年9市出生体重kg。
            p1  = 2.47;
            p3  = 2.62;
            p10 = 2.83;
            p25 = 3.06;
            p50 = 3.32;
            p75 = 3.59;
            p90 = 3.85;
            p97 = 4.12;
            p99 = 4.33;
        } else {
            p1  = 2.44;
            p3  = 2.57;
            p10 = 2.76;
            p25 = 2.96;
            p50 = 3.21;
            p75 = 3.49;
            p90 = 3.75;
            p97 = 4.04;
            p99 = 4.27;
        }
        if (value < p1) {
            percent = "<1%";
        } else if (value >= p1 && value < p3) {
            percent = "1%~3%";
            double a = (p3 - p1) / 2;
            double b = value - p1;
            double c = b / a;
            percent = Math.round(1 + c) + "%";
        } else if (value >= p3 && value < p10) {
            percent = "3%~10%";
            double a = (p10 - p3) / 7;
            double b = value - p3;
            double c = b / a;
            percent = Math.round(3 + c) + "%";
        } else if (value >= p10 && value < p25) {
            percent = "10%~25%";
            double a = (p25 - p10) / 15;
            double b = value - p10;
            double c = b / a;
            percent = Math.round(10 + c) + "%";
        }else if (value >= p25 && value < p50) {
            percent = "25%~50%";
            double a = (p50 - p25) / 25;
            double b = value - p25;
            double c = b / a;
            percent = Math.round(25 + c) + "%";
        } else if (value >= p50 && value <= p75) {
            percent = "50%~75%";
            double a = (p75 - p50) / 25;
            double b = value - p50;
            double c = b / a;
            percent = Math.round(50 + c) + "%";
        } else if (value > p75 && value <= p90) {
            percent = "75%~90%";
            double a = (p90 - p75) / 15;
            double b = value - p75;
            double c = b / a;
            percent = Math.round(75 + c) + "%";
        } else if (value > p90 && value <= p97) {
            percent = "90%~97%";
            double a = (p97 - p90) / 7;
            double b = value - p90;
            double c = b / a;
            percent = Math.round(90 + c) + "%";
        } else if (value > p97 && value <= p99) {
            percent = "97%~99%";
            double a = (p99 - p97) / 5;
            double b = value - p97;
            double c = b / a;
            percent = Math.round(97 + c) + "%";
        } else if (value > p99) {
            percent = ">99.9%";
        }
        retMap.put("percentiles", percent);
        retMap.put("msg",   "已计算了出生体重P值；");
        return retMap;
    }
}
